home *** CD-ROM | disk | FTP | other *** search
open in:
MacOS 8.1
|
Win98
|
DOS
browse contents |
view JSON data
|
view as text
This file was processed as: Mailbox/MIME Entity
(archive/mbox).
Confidence | Program | Detection | Match Type | Support
|
---|
100%
| dexvert
| Mailbox/MIME Entity (archive/mbox)
| magic
| Supported |
100%
| dexvert
| Internet Message Format (text/imf)
| magic
| Supported |
1%
| dexvert
| Text File (text/txt)
| fallback
| Supported |
100%
| file
| Mailbox text, 1st line "From scs@eskimo.com Fri Oct 14 22:09:13 1994"
| default
| |
99%
| file
| JavaScript source, ASCII text
| default (weak)
| |
100%
| TrID
| E-Mail message (Var. 2)
| default
| |
100%
| checkBytes
| Printable ASCII
| default
| |
100%
| perlTextCheck
| Likely Text (Perl)
| default
| |
100%
| siegfried
| x-fmt/111 Plain Text File
| default
| |
100%
| detectItEasy
| Format: plain text[LF]
| default (weak)
| |
100%
| xdgMime
| application/mbox
| default
|
|
hex view+--------+-------------------------+-------------------------+--------+--------+
|00000000| 46 72 6f 6d 20 73 63 73 | 40 65 73 6b 69 6d 6f 2e |From scs|@eskimo.|
|00000010| 63 6f 6d 20 46 72 69 20 | 4f 63 74 20 31 34 20 32 |com Fri |Oct 14 2|
|00000020| 32 3a 30 39 3a 31 33 20 | 31 39 39 34 0a 4e 65 77 |2:09:13 |1994.New|
|00000030| 73 67 72 6f 75 70 73 3a | 20 63 6f 6d 70 2e 6c 61 |sgroups:| comp.la|
|00000040| 6e 67 2e 63 2c 63 6f 6d | 70 2e 61 6e 73 77 65 72 |ng.c,com|p.answer|
|00000050| 73 2c 6e 65 77 73 2e 61 | 6e 73 77 65 72 73 0a 46 |s,news.a|nswers.F|
|00000060| 72 6f 6d 3a 20 73 63 73 | 40 65 73 6b 69 6d 6f 2e |rom: scs|@eskimo.|
|00000070| 63 6f 6d 20 28 53 74 65 | 76 65 20 53 75 6d 6d 69 |com (Ste|ve Summi|
|00000080| 74 29 0a 53 75 62 6a 65 | 63 74 3a 20 63 6f 6d 70 |t).Subje|ct: comp|
|00000090| 2e 6c 61 6e 67 2e 63 20 | 41 6e 73 77 65 72 73 20 |.lang.c |Answers |
|000000a0| 28 41 62 72 69 64 67 65 | 64 29 20 74 6f 20 46 72 |(Abridge|d) to Fr|
|000000b0| 65 71 75 65 6e 74 6c 79 | 20 41 73 6b 65 64 20 51 |equently| Asked Q|
|000000c0| 75 65 73 74 69 6f 6e 73 | 20 28 46 41 51 29 0a 46 |uestions| (FAQ).F|
|000000d0| 6f 6c 6c 6f 77 75 70 2d | 54 6f 3a 20 70 6f 73 74 |ollowup-|To: post|
|000000e0| 65 72 0a 53 75 6d 6d 61 | 72 79 3a 20 53 68 6f 72 |er.Summa|ry: Shor|
|000000f0| 74 20 61 6e 73 77 65 72 | 73 20 66 6f 72 20 74 68 |t answer|s for th|
|00000100| 6f 73 65 20 77 68 6f 20 | 64 6f 6e 27 74 20 63 61 |ose who |don't ca|
|00000110| 72 65 20 74 6f 20 72 65 | 61 64 20 74 68 65 20 6c |re to re|ad the l|
|00000120| 6f 6e 67 65 72 20 65 78 | 70 6c 61 6e 61 74 69 6f |onger ex|planatio|
|00000130| 6e 73 0a 53 75 70 65 72 | 73 65 64 65 73 3a 20 3c |ns.Super|sedes: <|
|00000140| 31 39 39 34 53 65 70 31 | 35 2e 30 33 30 30 2e 73 |1994Sep1|5.0300.s|
|00000150| 63 73 2e 30 30 30 31 40 | 65 73 6b 69 6d 6f 2e 63 |cs.0001@|eskimo.c|
|00000160| 6f 6d 3e 0a 52 65 70 6c | 79 2d 54 6f 3a 20 73 63 |om>.Repl|y-To: sc|
|00000170| 73 40 65 73 6b 69 6d 6f | 2e 63 6f 6d 0a 58 2d 41 |s@eskimo|.com.X-A|
|00000180| 72 63 68 69 76 65 2d 4e | 61 6d 65 3a 20 43 2d 66 |rchive-N|ame: C-f|
|00000190| 61 71 2f 61 62 72 69 64 | 67 65 64 0a 4f 72 67 61 |aq/abrid|ged.Orga|
|000001a0| 6e 69 7a 61 74 69 6f 6e | 3a 20 6e 6f 6e 65 2c 20 |nization|: none, |
|000001b0| 61 74 20 74 68 65 20 6d | 6f 6d 65 6e 74 0a 44 61 |at the m|oment.Da|
|000001c0| 74 65 3a 20 53 61 74 2c | 20 31 20 4f 63 74 20 31 |te: Sat,| 1 Oct 1|
|000001d0| 39 39 34 20 31 30 3a 30 | 32 3a 30 33 20 47 4d 54 |994 10:0|2:03 GMT|
|000001e0| 0a 58 2d 4c 61 73 74 2d | 4d 6f 64 69 66 69 65 64 |.X-Last-|Modified|
|000001f0| 3a 20 41 70 72 69 6c 20 | 31 36 2c 20 31 39 39 34 |: April |16, 1994|
|00000200| 0a 0a 41 72 63 68 69 76 | 65 2d 6e 61 6d 65 3a 20 |..Archiv|e-name: |
|00000210| 43 2d 66 61 71 2f 61 62 | 72 69 64 67 65 64 0a 43 |C-faq/ab|ridged.C|
|00000220| 6f 6d 70 2d 6c 61 6e 67 | 2d 63 2d 61 72 63 68 69 |omp-lang|-c-archi|
|00000230| 76 65 2d 6e 61 6d 65 3a | 20 43 2d 46 41 51 2d 6c |ve-name:| C-FAQ-l|
|00000240| 69 73 74 2e 61 62 72 69 | 64 67 65 64 0a 0a 5b 4c |ist.abri|dged..[L|
|00000250| 61 73 74 20 6d 6f 64 69 | 66 69 65 64 20 41 70 72 |ast modi|fied Apr|
|00000260| 69 6c 20 31 36 2c 20 31 | 39 39 34 20 62 79 20 73 |il 16, 1|994 by s|
|00000270| 63 73 2e 5d 0a 0a 54 68 | 69 73 20 61 72 74 69 63 |cs.]..Th|is artic|
|00000280| 6c 65 20 63 6f 6e 74 61 | 69 6e 73 20 6d 69 6e 69 |le conta|ins mini|
|00000290| 6d 61 6c 20 61 6e 73 77 | 65 72 73 20 74 6f 20 74 |mal answ|ers to t|
|000002a0| 68 65 20 63 6f 6d 70 2e | 6c 61 6e 67 2e 63 20 66 |he comp.|lang.c f|
|000002b0| 72 65 71 75 65 6e 74 6c | 79 2d 0a 61 73 6b 65 64 |requentl|y-.asked|
|000002c0| 20 71 75 65 73 74 69 6f | 6e 73 20 6c 69 73 74 2e | questio|ns list.|
|000002d0| 20 20 50 6c 65 61 73 65 | 20 73 65 65 20 74 68 65 | Please| see the|
|000002e0| 20 6c 6f 6e 67 20 76 65 | 72 73 69 6f 6e 20 28 73 | long ve|rsion (s|
|000002f0| 65 65 20 71 75 65 73 74 | 69 6f 6e 20 31 37 2e 33 |ee quest|ion 17.3|
|00000300| 33 0a 66 6f 72 20 61 76 | 61 69 6c 61 62 69 6c 69 |3.for av|ailabili|
|00000310| 74 79 29 20 66 6f 72 20 | 6d 6f 72 65 20 64 65 74 |ty) for |more det|
|00000320| 61 69 6c 65 64 20 65 78 | 70 6c 61 6e 61 74 69 6f |ailed ex|planatio|
|00000330| 6e 73 20 61 6e 64 20 72 | 65 66 65 72 65 6e 63 65 |ns and r|eference|
|00000340| 73 2e 0a 0a 0a 53 65 63 | 74 69 6f 6e 20 31 2e 20 |s....Sec|tion 1. |
|00000350| 4e 75 6c 6c 20 50 6f 69 | 6e 74 65 72 73 0a 0a 31 |Null Poi|nters..1|
|00000360| 2e 31 3a 09 57 68 61 74 | 20 69 73 20 74 68 69 73 |.1:.What| is this|
|00000370| 20 69 6e 66 61 6d 6f 75 | 73 20 6e 75 6c 6c 20 70 | infamou|s null p|
|00000380| 6f 69 6e 74 65 72 2c 20 | 61 6e 79 77 61 79 3f 0a |ointer, |anyway?.|
|00000390| 0a 41 3a 09 46 6f 72 20 | 65 61 63 68 20 70 6f 69 |.A:.For |each poi|
|000003a0| 6e 74 65 72 20 74 79 70 | 65 2c 20 74 68 65 72 65 |nter typ|e, there|
|000003b0| 20 69 73 20 61 20 73 70 | 65 63 69 61 6c 20 76 61 | is a sp|ecial va|
|000003c0| 6c 75 65 20 2d 2d 20 74 | 68 65 20 22 6e 75 6c 6c |lue -- t|he "null|
|000003d0| 0a 09 70 6f 69 6e 74 65 | 72 22 20 2d 2d 20 77 68 |..pointe|r" -- wh|
|000003e0| 69 63 68 20 69 73 20 64 | 69 73 74 69 6e 67 75 69 |ich is d|istingui|
|000003f0| 73 68 61 62 6c 65 20 66 | 72 6f 6d 20 61 6c 6c 20 |shable f|rom all |
|00000400| 6f 74 68 65 72 20 70 6f | 69 6e 74 65 72 0a 09 76 |other po|inter..v|
|00000410| 61 6c 75 65 73 20 61 6e | 64 20 77 68 69 63 68 20 |alues an|d which |
|00000420| 69 73 20 6e 6f 74 20 74 | 68 65 20 61 64 64 72 65 |is not t|he addre|
|00000430| 73 73 20 6f 66 20 61 6e | 79 20 6f 62 6a 65 63 74 |ss of an|y object|
|00000440| 20 6f 72 20 66 75 6e 63 | 74 69 6f 6e 2e 0a 0a 31 | or func|tion...1|
|00000450| 2e 32 3a 09 48 6f 77 20 | 64 6f 20 49 20 22 67 65 |.2:.How |do I "ge|
|00000460| 74 22 20 61 20 6e 75 6c | 6c 20 70 6f 69 6e 74 65 |t" a nul|l pointe|
|00000470| 72 20 69 6e 20 6d 79 20 | 70 72 6f 67 72 61 6d 73 |r in my |programs|
|00000480| 3f 0a 0a 41 3a 09 41 20 | 63 6f 6e 73 74 61 6e 74 |?..A:.A |constant|
|00000490| 20 30 20 69 6e 20 61 20 | 70 6f 69 6e 74 65 72 20 | 0 in a |pointer |
|000004a0| 63 6f 6e 74 65 78 74 20 | 69 73 20 63 6f 6e 76 65 |context |is conve|
|000004b0| 72 74 65 64 20 69 6e 74 | 6f 20 61 20 6e 75 6c 6c |rted int|o a null|
|000004c0| 0a 09 70 6f 69 6e 74 65 | 72 20 61 74 20 63 6f 6d |..pointe|r at com|
|000004d0| 70 69 6c 65 20 74 69 6d | 65 2e 20 20 41 20 22 70 |pile tim|e. A "p|
|000004e0| 6f 69 6e 74 65 72 20 63 | 6f 6e 74 65 78 74 22 20 |ointer c|ontext" |
|000004f0| 69 73 20 61 6e 0a 09 69 | 6e 69 74 69 61 6c 69 7a |is an..i|nitializ|
|00000500| 61 74 69 6f 6e 2c 20 61 | 73 73 69 67 6e 6d 65 6e |ation, a|ssignmen|
|00000510| 74 2c 20 6f 72 20 63 6f | 6d 70 61 72 69 73 6f 6e |t, or co|mparison|
|00000520| 20 77 69 74 68 20 6f 6e | 65 20 73 69 64 65 20 61 | with on|e side a|
|00000530| 0a 09 76 61 72 69 61 62 | 6c 65 20 6f 72 20 65 78 |..variab|le or ex|
|00000540| 70 72 65 73 73 69 6f 6e | 20 6f 66 20 70 6f 69 6e |pression| of poin|
|00000550| 74 65 72 20 74 79 70 65 | 2c 20 61 6e 64 20 28 69 |ter type|, and (i|
|00000560| 6e 20 41 4e 53 49 20 73 | 74 61 6e 64 61 72 64 20 |n ANSI s|tandard |
|00000570| 43 29 0a 09 61 20 66 75 | 6e 63 74 69 6f 6e 20 61 |C)..a fu|nction a|
|00000580| 72 67 75 6d 65 6e 74 20 | 77 68 69 63 68 20 68 61 |rgument |which ha|
|00000590| 73 20 61 20 70 72 6f 74 | 6f 74 79 70 65 20 69 6e |s a prot|otype in|
|000005a0| 20 73 63 6f 70 65 20 64 | 65 63 6c 61 72 69 6e 67 | scope d|eclaring|
|000005b0| 20 61 0a 09 63 65 72 74 | 61 69 6e 20 70 61 72 61 | a..cert|ain para|
|000005c0| 6d 65 74 65 72 20 61 73 | 20 62 65 69 6e 67 20 6f |meter as| being o|
|000005d0| 66 20 70 6f 69 6e 74 65 | 72 20 74 79 70 65 2e 20 |f pointe|r type. |
|000005e0| 20 49 6e 20 6f 74 68 65 | 72 20 63 6f 6e 74 65 78 | In othe|r contex|
|000005f0| 74 73 0a 09 28 66 75 6e | 63 74 69 6f 6e 20 61 72 |ts..(fun|ction ar|
|00000600| 67 75 6d 65 6e 74 73 20 | 77 69 74 68 6f 75 74 20 |guments |without |
|00000610| 70 72 6f 74 6f 74 79 70 | 65 73 2c 20 6f 72 20 69 |prototyp|es, or i|
|00000620| 6e 20 74 68 65 20 76 61 | 72 69 61 62 6c 65 20 70 |n the va|riable p|
|00000630| 61 72 74 0a 09 6f 66 20 | 76 61 72 69 61 64 69 63 |art..of |variadic|
|00000640| 20 66 75 6e 63 74 69 6f | 6e 20 63 61 6c 6c 73 29 | functio|n calls)|
|00000650| 20 61 20 63 6f 6e 73 74 | 61 6e 74 20 30 20 77 69 | a const|ant 0 wi|
|00000660| 74 68 20 61 6e 20 61 70 | 70 72 6f 70 72 69 61 74 |th an ap|propriat|
|00000670| 65 0a 09 65 78 70 6c 69 | 63 69 74 20 63 61 73 74 |e..expli|cit cast|
|00000680| 20 69 73 20 72 65 71 75 | 69 72 65 64 2e 0a 0a 31 | is requ|ired...1|
|00000690| 2e 33 3a 09 57 68 61 74 | 20 69 73 20 4e 55 4c 4c |.3:.What| is NULL|
|000006a0| 20 61 6e 64 20 68 6f 77 | 20 69 73 20 69 74 20 23 | and how| is it #|
|000006b0| 64 65 66 69 6e 65 64 3f | 0a 0a 41 3a 09 4e 55 4c |defined?|..A:.NUL|
|000006c0| 4c 20 69 73 20 73 69 6d | 70 6c 79 20 61 20 70 72 |L is sim|ply a pr|
|000006d0| 65 70 72 6f 63 65 73 73 | 6f 72 20 6d 61 63 72 6f |eprocess|or macro|
|000006e0| 2c 20 23 64 65 66 69 6e | 65 64 20 61 73 20 30 20 |, #defin|ed as 0 |
|000006f0| 28 6f 72 0a 09 28 76 6f | 69 64 20 2a 29 30 29 2c |(or..(vo|id *)0),|
|00000700| 20 77 68 69 63 68 20 69 | 73 20 75 73 65 64 20 28 | which i|s used (|
|00000710| 61 73 20 61 20 73 74 79 | 6c 69 73 74 69 63 20 63 |as a sty|listic c|
|00000720| 6f 6e 76 65 6e 74 69 6f | 6e 2c 20 69 6e 0a 09 70 |onventio|n, in..p|
|00000730| 72 65 66 65 72 65 6e 63 | 65 20 74 6f 20 75 6e 61 |referenc|e to una|
|00000740| 64 6f 72 6e 65 64 20 30 | 27 73 29 20 74 6f 20 67 |dorned 0|'s) to g|
|00000750| 65 6e 65 72 61 74 65 20 | 6e 75 6c 6c 20 70 6f 69 |enerate |null poi|
|00000760| 6e 74 65 72 73 2c 0a 0a | 31 2e 34 3a 09 48 6f 77 |nters,..|1.4:.How|
|00000770| 20 73 68 6f 75 6c 64 20 | 4e 55 4c 4c 20 62 65 20 | should |NULL be |
|00000780| 23 64 65 66 69 6e 65 64 | 20 6f 6e 20 61 20 6d 61 |#defined| on a ma|
|00000790| 63 68 69 6e 65 20 77 68 | 69 63 68 20 75 73 65 73 |chine wh|ich uses|
|000007a0| 20 61 20 6e 6f 6e 7a 65 | 72 6f 0a 09 62 69 74 20 | a nonze|ro..bit |
|000007b0| 70 61 74 74 65 72 6e 20 | 61 73 20 74 68 65 20 69 |pattern |as the i|
|000007c0| 6e 74 65 72 6e 61 6c 20 | 72 65 70 72 65 73 65 6e |nternal |represen|
|000007d0| 74 61 74 69 6f 6e 20 6f | 66 20 61 20 6e 75 6c 6c |tation o|f a null|
|000007e0| 20 70 6f 69 6e 74 65 72 | 3f 0a 0a 41 3a 09 54 68 | pointer|?..A:.Th|
|000007f0| 65 20 73 61 6d 65 20 61 | 73 20 61 6e 79 20 6f 74 |e same a|s any ot|
|00000800| 68 65 72 20 6d 61 63 68 | 69 6e 65 3a 20 61 73 20 |her mach|ine: as |
|00000810| 30 20 28 6f 72 20 28 76 | 6f 69 64 20 2a 29 30 29 |0 (or (v|oid *)0)|
|00000820| 2e 20 20 28 54 68 65 0a | 09 63 6f 6d 70 69 6c 65 |. (The.|.compile|
|00000830| 72 20 6d 61 6b 65 73 20 | 74 68 65 20 74 72 61 6e |r makes |the tran|
|00000840| 73 6c 61 74 69 6f 6e 2c | 20 75 70 6f 6e 20 73 65 |slation,| upon se|
|00000850| 65 69 6e 67 20 61 20 30 | 2c 20 6e 6f 74 20 74 68 |eing a 0|, not th|
|00000860| 65 0a 09 70 72 65 70 72 | 6f 63 65 73 73 6f 72 2e |e..prepr|ocessor.|
|00000870| 29 0a 0a 31 2e 35 3a 09 | 49 66 20 4e 55 4c 4c 20 |)..1.5:.|If NULL |
|00000880| 77 65 72 65 20 64 65 66 | 69 6e 65 64 20 61 73 20 |were def|ined as |
|00000890| 22 28 28 63 68 61 72 20 | 2a 29 30 29 2c 22 20 77 |"((char |*)0)," w|
|000008a0| 6f 75 6c 64 6e 27 74 20 | 74 68 61 74 20 6d 61 6b |ouldn't |that mak|
|000008b0| 65 0a 09 66 75 6e 63 74 | 69 6f 6e 20 63 61 6c 6c |e..funct|ion call|
|000008c0| 73 20 77 68 69 63 68 20 | 70 61 73 73 20 61 6e 20 |s which |pass an |
|000008d0| 75 6e 63 61 73 74 20 4e | 55 4c 4c 20 77 6f 72 6b |uncast N|ULL work|
|000008e0| 3f 0a 0a 41 3a 09 4e 6f | 74 20 69 6e 20 67 65 6e |?..A:.No|t in gen|
|000008f0| 65 72 61 6c 2e 20 20 54 | 68 65 20 70 72 6f 62 6c |eral. T|he probl|
|00000900| 65 6d 20 69 73 20 74 68 | 61 74 20 74 68 65 72 65 |em is th|at there|
|00000910| 20 61 72 65 20 6d 61 63 | 68 69 6e 65 73 20 77 68 | are mac|hines wh|
|00000920| 69 63 68 0a 09 75 73 65 | 20 64 69 66 66 65 72 65 |ich..use| differe|
|00000930| 6e 74 20 69 6e 74 65 72 | 6e 61 6c 20 72 65 70 72 |nt inter|nal repr|
|00000940| 65 73 65 6e 74 61 74 69 | 6f 6e 73 20 66 6f 72 20 |esentati|ons for |
|00000950| 70 6f 69 6e 74 65 72 73 | 20 74 6f 20 64 69 66 66 |pointers| to diff|
|00000960| 65 72 65 6e 74 0a 09 74 | 79 70 65 73 20 6f 66 20 |erent..t|ypes of |
|00000970| 64 61 74 61 2e 20 20 41 | 20 63 61 73 74 20 69 73 |data. A| cast is|
|00000980| 20 73 74 69 6c 6c 20 72 | 65 71 75 69 72 65 64 20 | still r|equired |
|00000990| 74 6f 20 74 65 6c 6c 20 | 74 68 65 20 63 6f 6d 70 |to tell |the comp|
|000009a0| 69 6c 65 72 0a 09 77 68 | 69 63 68 20 6b 69 6e 64 |iler..wh|ich kind|
|000009b0| 20 6f 66 20 6e 75 6c 6c | 20 70 6f 69 6e 74 65 72 | of null| pointer|
|000009c0| 20 69 73 20 72 65 71 75 | 69 72 65 64 2c 20 73 69 | is requ|ired, si|
|000009d0| 6e 63 65 20 69 74 20 6d | 61 79 20 62 65 0a 09 64 |nce it m|ay be..d|
|000009e0| 69 66 66 65 72 65 6e 74 | 20 66 72 6f 6d 20 28 63 |ifferent| from (c|
|000009f0| 68 61 72 20 2a 29 30 2e | 0a 0a 31 2e 36 3a 09 49 |har *)0.|..1.6:.I|
|00000a00| 20 75 73 65 20 74 68 65 | 20 70 72 65 70 72 6f 63 | use the| preproc|
|00000a10| 65 73 73 6f 72 20 6d 61 | 63 72 6f 20 22 23 64 65 |essor ma|cro "#de|
|00000a20| 66 69 6e 65 20 4e 75 6c | 6c 70 74 72 28 74 79 70 |fine Nul|lptr(typ|
|00000a30| 65 29 20 28 74 79 70 65 | 20 2a 29 30 22 0a 09 74 |e) (type| *)0"..t|
|00000a40| 6f 20 68 65 6c 70 20 6d | 65 20 62 75 69 6c 64 20 |o help m|e build |
|00000a50| 6e 75 6c 6c 20 70 6f 69 | 6e 74 65 72 73 20 6f 66 |null poi|nters of|
|00000a60| 20 74 68 65 20 63 6f 72 | 72 65 63 74 20 74 79 70 | the cor|rect typ|
|00000a70| 65 2e 0a 0a 41 3a 09 54 | 68 69 73 20 74 72 69 63 |e...A:.T|his tric|
|00000a80| 6b 2c 20 74 68 6f 75 67 | 68 20 76 61 6c 69 64 2c |k, thoug|h valid,|
|00000a90| 20 64 6f 65 73 20 6e 6f | 74 20 62 75 79 20 6d 75 | does no|t buy mu|
|00000aa0| 63 68 2e 0a 0a 31 2e 37 | 3a 09 49 73 20 74 68 65 |ch...1.7|:.Is the|
|00000ab0| 20 61 62 62 72 65 76 69 | 61 74 65 64 20 70 6f 69 | abbrevi|ated poi|
|00000ac0| 6e 74 65 72 20 63 6f 6d | 70 61 72 69 73 6f 6e 20 |nter com|parison |
|00000ad0| 22 69 66 28 70 29 22 20 | 74 6f 20 74 65 73 74 20 |"if(p)" |to test |
|00000ae0| 66 6f 72 20 6e 6f 6e 2d | 0a 09 6e 75 6c 6c 20 70 |for non-|..null p|
|00000af0| 6f 69 6e 74 65 72 73 20 | 76 61 6c 69 64 3f 20 20 |ointers |valid? |
|00000b00| 57 68 61 74 20 69 66 20 | 74 68 65 20 69 6e 74 65 |What if |the inte|
|00000b10| 72 6e 61 6c 20 72 65 70 | 72 65 73 65 6e 74 61 74 |rnal rep|resentat|
|00000b20| 69 6f 6e 20 66 6f 72 0a | 09 6e 75 6c 6c 20 70 6f |ion for.|.null po|
|00000b30| 69 6e 74 65 72 73 20 69 | 73 20 6e 6f 6e 7a 65 72 |inters i|s nonzer|
|00000b40| 6f 3f 0a 0a 41 3a 09 54 | 68 65 20 63 6f 6e 73 74 |o?..A:.T|he const|
|00000b50| 72 75 63 74 69 6f 6e 20 | 22 69 66 28 70 29 22 20 |ruction |"if(p)" |
|00000b60| 77 6f 72 6b 73 2c 20 72 | 65 67 61 72 64 6c 65 73 |works, r|egardles|
|00000b70| 73 20 6f 66 20 74 68 65 | 20 69 6e 74 65 72 6e 61 |s of the| interna|
|00000b80| 6c 0a 09 72 65 70 72 65 | 73 65 6e 74 61 74 69 6f |l..repre|sentatio|
|00000b90| 6e 20 6f 66 20 6e 75 6c | 6c 20 70 6f 69 6e 74 65 |n of nul|l pointe|
|00000ba0| 72 73 2c 20 62 65 63 61 | 75 73 65 20 74 68 65 20 |rs, beca|use the |
|00000bb0| 63 6f 6d 70 69 6c 65 72 | 0a 09 65 73 73 65 6e 74 |compiler|..essent|
|00000bc0| 69 61 6c 6c 79 20 72 65 | 77 72 69 74 65 73 20 69 |ially re|writes i|
|00000bd0| 74 20 61 73 20 22 69 66 | 28 70 20 21 3d 20 30 29 |t as "if|(p != 0)|
|00000be0| 22 20 61 6e 64 20 67 6f | 65 73 20 6f 6e 20 74 6f |" and go|es on to|
|00000bf0| 20 63 6f 6e 76 65 72 74 | 20 30 0a 09 69 6e 74 6f | convert| 0..into|
|00000c00| 20 74 68 65 20 63 6f 72 | 72 65 63 74 20 6e 75 6c | the cor|rect nul|
|00000c10| 6c 20 70 6f 69 6e 74 65 | 72 2e 0a 0a 31 2e 38 3a |l pointe|r...1.8:|
|00000c20| 09 49 66 20 22 4e 55 4c | 4c 22 20 61 6e 64 20 22 |.If "NUL|L" and "|
|00000c30| 30 22 20 61 72 65 20 65 | 71 75 69 76 61 6c 65 6e |0" are e|quivalen|
|00000c40| 74 2c 20 77 68 69 63 68 | 20 73 68 6f 75 6c 64 20 |t, which| should |
|00000c50| 49 20 75 73 65 3f 0a 0a | 41 3a 09 45 69 74 68 65 |I use?..|A:.Eithe|
|00000c60| 72 3b 20 74 68 65 20 64 | 69 73 74 69 6e 63 74 69 |r; the d|istincti|
|00000c70| 6f 6e 20 69 73 20 65 6e | 74 69 72 65 6c 79 20 73 |on is en|tirely s|
|00000c80| 74 79 6c 69 73 74 69 63 | 2e 0a 0a 31 2e 39 3a 09 |tylistic|...1.9:.|
|00000c90| 42 75 74 20 77 6f 75 6c | 64 6e 27 74 20 69 74 20 |But woul|dn't it |
|00000ca0| 62 65 20 62 65 74 74 65 | 72 20 74 6f 20 75 73 65 |be bette|r to use|
|00000cb0| 20 4e 55 4c 4c 20 28 72 | 61 74 68 65 72 20 74 68 | NULL (r|ather th|
|00000cc0| 61 6e 20 30 29 20 69 6e | 20 63 61 73 65 0a 09 74 |an 0) in| case..t|
|00000cd0| 68 65 20 76 61 6c 75 65 | 20 6f 66 20 4e 55 4c 4c |he value| of NULL|
|00000ce0| 20 63 68 61 6e 67 65 73 | 2c 20 70 65 72 68 61 70 | changes|, perhap|
|00000cf0| 73 20 6f 6e 20 61 20 6d | 61 63 68 69 6e 65 20 77 |s on a m|achine w|
|00000d00| 69 74 68 20 6e 6f 6e 7a | 65 72 6f 0a 09 6e 75 6c |ith nonz|ero..nul|
|00000d10| 6c 20 70 6f 69 6e 74 65 | 72 73 3f 0a 0a 41 3a 09 |l pointe|rs?..A:.|
|00000d20| 4e 6f 2e 20 20 4e 55 4c | 4c 20 69 73 2c 20 61 6e |No. NUL|L is, an|
|00000d30| 64 20 77 69 6c 6c 20 61 | 6c 77 61 79 73 20 62 65 |d will a|lways be|
|00000d40| 2c 20 30 2e 0a 0a 31 2e | 31 30 3a 09 49 27 6d 20 |, 0...1.|10:.I'm |
|00000d50| 63 6f 6e 66 75 73 65 64 | 2e 20 20 4e 55 4c 4c 20 |confused|. NULL |
|00000d60| 69 73 20 67 75 61 72 61 | 6e 74 65 65 64 20 74 6f |is guara|nteed to|
|00000d70| 20 62 65 20 30 2c 20 62 | 75 74 20 74 68 65 20 6e | be 0, b|ut the n|
|00000d80| 75 6c 6c 20 70 6f 69 6e | 74 65 72 0a 09 69 73 20 |ull poin|ter..is |
|00000d90| 6e 6f 74 3f 0a 0a 41 3a | 09 41 20 22 6e 75 6c 6c |not?..A:|.A "null|
|00000da0| 20 70 6f 69 6e 74 65 72 | 22 20 69 73 20 61 20 6c | pointer|" is a l|
|00000db0| 61 6e 67 75 61 67 65 20 | 63 6f 6e 63 65 70 74 20 |anguage |concept |
|00000dc0| 77 68 6f 73 65 20 70 61 | 72 74 69 63 75 6c 61 72 |whose pa|rticular|
|00000dd0| 20 69 6e 74 65 72 6e 61 | 6c 0a 09 76 61 6c 75 65 | interna|l..value|
|00000de0| 20 64 6f 65 73 20 6e 6f | 74 20 6d 61 74 74 65 72 | does no|t matter|
|00000df0| 2e 20 20 41 20 6e 75 6c | 6c 20 70 6f 69 6e 74 65 |. A nul|l pointe|
|00000e00| 72 20 69 73 20 72 65 71 | 75 65 73 74 65 64 20 69 |r is req|uested i|
|00000e10| 6e 20 73 6f 75 72 63 65 | 0a 09 63 6f 64 65 20 77 |n source|..code w|
|00000e20| 69 74 68 20 74 68 65 20 | 63 68 61 72 61 63 74 65 |ith the |characte|
|00000e30| 72 20 22 30 22 2e 20 20 | 22 4e 55 4c 4c 22 20 69 |r "0". |"NULL" i|
|00000e40| 73 20 61 20 70 72 65 70 | 72 6f 63 65 73 73 6f 72 |s a prep|rocessor|
|00000e50| 20 6d 61 63 72 6f 2c 0a | 09 77 68 69 63 68 20 69 | macro,.|.which i|
|00000e60| 73 20 61 6c 77 61 79 73 | 20 23 64 65 66 69 6e 65 |s always| #define|
|00000e70| 64 20 61 73 20 30 20 28 | 6f 72 20 28 76 6f 69 64 |d as 0 (|or (void|
|00000e80| 20 2a 29 30 29 2e 0a 0a | 31 2e 31 31 3a 09 57 68 | *)0)...|1.11:.Wh|
|00000e90| 79 20 69 73 20 74 68 65 | 72 65 20 73 6f 20 6d 75 |y is the|re so mu|
|00000ea0| 63 68 20 63 6f 6e 66 75 | 73 69 6f 6e 20 73 75 72 |ch confu|sion sur|
|00000eb0| 72 6f 75 6e 64 69 6e 67 | 20 6e 75 6c 6c 20 70 6f |rounding| null po|
|00000ec0| 69 6e 74 65 72 73 3f 20 | 20 57 68 79 0a 09 64 6f |inters? | Why..do|
|00000ed0| 20 74 68 65 73 65 20 71 | 75 65 73 74 69 6f 6e 73 | these q|uestions|
|00000ee0| 20 63 6f 6d 65 20 75 70 | 20 73 6f 20 6f 66 74 65 | come up| so ofte|
|00000ef0| 6e 3f 0a 0a 41 3a 09 54 | 68 65 20 66 61 63 74 20 |n?..A:.T|he fact |
|00000f00| 74 68 61 74 20 6e 75 6c | 6c 20 70 6f 69 6e 74 65 |that nul|l pointe|
|00000f10| 72 73 20 61 72 65 20 72 | 65 70 72 65 73 65 6e 74 |rs are r|epresent|
|00000f20| 65 64 20 62 6f 74 68 20 | 69 6e 20 73 6f 75 72 63 |ed both |in sourc|
|00000f30| 65 20 63 6f 64 65 2c 0a | 09 61 6e 64 20 69 6e 74 |e code,.|.and int|
|00000f40| 65 72 6e 61 6c 6c 79 20 | 74 6f 20 6d 6f 73 74 20 |ernally |to most |
|00000f50| 6d 61 63 68 69 6e 65 73 | 2c 20 61 73 20 7a 65 72 |machines|, as zer|
|00000f60| 6f 20 69 6e 76 69 74 65 | 73 20 75 6e 77 61 72 72 |o invite|s unwarr|
|00000f70| 61 6e 74 65 64 0a 09 61 | 73 73 75 6d 70 74 69 6f |anted..a|ssumptio|
|00000f80| 6e 73 2e 20 20 54 68 65 | 20 75 73 65 20 6f 66 20 |ns. The| use of |
|00000f90| 61 20 70 72 65 70 72 6f | 63 65 73 73 6f 72 20 6d |a prepro|cessor m|
|00000fa0| 61 63 72 6f 20 28 4e 55 | 4c 4c 29 20 73 75 67 67 |acro (NU|LL) sugg|
|00000fb0| 65 73 74 73 0a 09 74 68 | 61 74 20 74 68 65 20 76 |ests..th|at the v|
|00000fc0| 61 6c 75 65 20 6d 69 67 | 68 74 20 63 68 61 6e 67 |alue mig|ht chang|
|00000fd0| 65 20 6c 61 74 65 72 2c | 20 6f 72 20 6f 6e 20 73 |e later,| or on s|
|00000fe0| 6f 6d 65 20 77 65 69 72 | 64 20 6d 61 63 68 69 6e |ome weir|d machin|
|00000ff0| 65 2e 0a 0a 31 2e 31 32 | 3a 09 49 27 6d 20 73 74 |e...1.12|:.I'm st|
|00001000| 69 6c 6c 20 63 6f 6e 66 | 75 73 65 64 2e 20 20 49 |ill conf|used. I|
|00001010| 20 6a 75 73 74 20 63 61 | 6e 27 74 20 75 6e 64 65 | just ca|n't unde|
|00001020| 72 73 74 61 6e 64 20 61 | 6c 6c 20 74 68 69 73 20 |rstand a|ll this |
|00001030| 6e 75 6c 6c 0a 09 70 6f | 69 6e 74 65 72 20 73 74 |null..po|inter st|
|00001040| 75 66 66 2e 0a 0a 41 3a | 09 41 20 73 69 6d 70 6c |uff...A:|.A simpl|
|00001050| 65 20 72 75 6c 65 20 69 | 73 2c 20 22 41 6c 77 61 |e rule i|s, "Alwa|
|00001060| 79 73 20 75 73 65 20 60 | 30 27 20 6f 72 20 60 4e |ys use `|0' or `N|
|00001070| 55 4c 4c 27 20 66 6f 72 | 20 6e 75 6c 6c 20 70 6f |ULL' for| null po|
|00001080| 69 6e 74 65 72 73 2c 0a | 09 61 6e 64 20 61 6c 77 |inters,.|.and alw|
|00001090| 61 79 73 20 63 61 73 74 | 20 74 68 65 6d 20 77 68 |ays cast| them wh|
|000010a0| 65 6e 20 74 68 65 79 20 | 61 72 65 20 75 73 65 64 |en they |are used|
|000010b0| 20 61 73 20 61 72 67 75 | 6d 65 6e 74 73 20 69 6e | as argu|ments in|
|000010c0| 20 66 75 6e 63 74 69 6f | 6e 0a 09 63 61 6c 6c 73 | functio|n..calls|
|000010d0| 2e 22 0a 0a 31 2e 31 33 | 3a 09 47 69 76 65 6e 20 |."..1.13|:.Given |
|000010e0| 61 6c 6c 20 74 68 65 20 | 63 6f 6e 66 75 73 69 6f |all the |confusio|
|000010f0| 6e 20 73 75 72 72 6f 75 | 6e 64 69 6e 67 20 6e 75 |n surrou|nding nu|
|00001100| 6c 6c 20 70 6f 69 6e 74 | 65 72 73 2c 20 77 6f 75 |ll point|ers, wou|
|00001110| 6c 64 6e 27 74 20 69 74 | 0a 09 62 65 20 65 61 73 |ldn't it|..be eas|
|00001120| 69 65 72 20 73 69 6d 70 | 6c 79 20 74 6f 20 72 65 |ier simp|ly to re|
|00001130| 71 75 69 72 65 20 74 68 | 65 6d 20 74 6f 20 62 65 |quire th|em to be|
|00001140| 20 72 65 70 72 65 73 65 | 6e 74 65 64 20 69 6e 74 | represe|nted int|
|00001150| 65 72 6e 61 6c 6c 79 20 | 62 79 0a 09 7a 65 72 6f |ernally |by..zero|
|00001160| 65 73 3f 0a 0a 41 3a 09 | 53 75 63 68 20 61 20 72 |es?..A:.|Such a r|
|00001170| 65 71 75 69 72 65 6d 65 | 6e 74 20 77 6f 75 6c 64 |equireme|nt would|
|00001180| 20 61 63 63 6f 6d 70 6c | 69 73 68 20 6c 69 74 74 | accompl|ish litt|
|00001190| 6c 65 2e 0a 0a 31 2e 31 | 34 3a 09 53 65 72 69 6f |le...1.1|4:.Serio|
|000011a0| 75 73 6c 79 2c 20 68 61 | 76 65 20 61 6e 79 20 61 |usly, ha|ve any a|
|000011b0| 63 74 75 61 6c 20 6d 61 | 63 68 69 6e 65 73 20 72 |ctual ma|chines r|
|000011c0| 65 61 6c 6c 79 20 75 73 | 65 64 20 6e 6f 6e 7a 65 |eally us|ed nonze|
|000011d0| 72 6f 20 6e 75 6c 6c 0a | 09 70 6f 69 6e 74 65 72 |ro null.|.pointer|
|000011e0| 73 3f 0a 0a 41 3a 09 4d | 61 63 68 69 6e 65 73 20 |s?..A:.M|achines |
|000011f0| 6d 61 6e 75 66 61 63 74 | 75 72 65 64 20 62 79 20 |manufact|ured by |
|00001200| 50 72 69 6d 65 2c 20 48 | 6f 6e 65 79 77 65 6c 6c |Prime, H|oneywell|
|00001210| 2d 42 75 6c 6c 2c 20 61 | 6e 64 20 43 44 43 2c 20 |-Bull, a|nd CDC, |
|00001220| 61 73 20 77 65 6c 6c 0a | 09 61 73 20 53 79 6d 62 |as well.|.as Symb|
|00001230| 6f 6c 69 63 73 20 4c 69 | 73 70 20 4d 61 63 68 69 |olics Li|sp Machi|
|00001240| 6e 65 73 2c 20 68 61 76 | 65 20 64 6f 6e 65 20 73 |nes, hav|e done s|
|00001250| 6f 2e 0a 0a 31 2e 31 35 | 3a 09 57 68 61 74 20 64 |o...1.15|:.What d|
|00001260| 6f 65 73 20 61 20 72 75 | 6e 2d 74 69 6d 65 20 22 |oes a ru|n-time "|
|00001270| 6e 75 6c 6c 20 70 6f 69 | 6e 74 65 72 20 61 73 73 |null poi|nter ass|
|00001280| 69 67 6e 6d 65 6e 74 22 | 20 65 72 72 6f 72 20 6d |ignment"| error m|
|00001290| 65 61 6e 3f 0a 0a 41 3a | 09 49 74 20 6d 65 61 6e |ean?..A:|.It mean|
|000012a0| 73 20 74 68 61 74 20 79 | 6f 75 27 76 65 20 77 72 |s that y|ou've wr|
|000012b0| 69 74 74 65 6e 20 74 68 | 72 6f 75 67 68 20 61 20 |itten th|rough a |
|000012c0| 6e 75 6c 6c 20 70 6f 69 | 6e 74 65 72 2e 0a 0a 0a |null poi|nter....|
|000012d0| 53 65 63 74 69 6f 6e 20 | 32 2e 20 41 72 72 61 79 |Section |2. Array|
|000012e0| 73 20 61 6e 64 20 50 6f | 69 6e 74 65 72 73 0a 0a |s and Po|inters..|
|000012f0| 32 2e 31 3a 09 49 20 68 | 61 64 20 74 68 65 20 64 |2.1:.I h|ad the d|
|00001300| 65 66 69 6e 69 74 69 6f | 6e 20 63 68 61 72 20 61 |efinitio|n char a|
|00001310| 5b 36 5d 20 69 6e 20 6f | 6e 65 20 73 6f 75 72 63 |[6] in o|ne sourc|
|00001320| 65 20 66 69 6c 65 2c 20 | 61 6e 64 20 69 6e 0a 09 |e file, |and in..|
|00001330| 61 6e 6f 74 68 65 72 20 | 49 20 64 65 63 6c 61 72 |another |I declar|
|00001340| 65 64 20 65 78 74 65 72 | 6e 20 63 68 61 72 20 2a |ed exter|n char *|
|00001350| 61 2e 20 20 57 68 79 20 | 64 69 64 6e 27 74 20 69 |a. Why |didn't i|
|00001360| 74 20 77 6f 72 6b 3f 0a | 0a 41 3a 09 54 68 65 20 |t work?.|.A:.The |
|00001370| 64 65 63 6c 61 72 61 74 | 69 6f 6e 20 65 78 74 65 |declarat|ion exte|
|00001380| 72 6e 20 63 68 61 72 20 | 2a 61 20 73 69 6d 70 6c |rn char |*a simpl|
|00001390| 79 20 64 6f 65 73 20 6e | 6f 74 20 6d 61 74 63 68 |y does n|ot match|
|000013a0| 20 74 68 65 20 61 63 74 | 75 61 6c 0a 09 64 65 66 | the act|ual..def|
|000013b0| 69 6e 69 74 69 6f 6e 2e | 20 20 55 73 65 20 65 78 |inition.| Use ex|
|000013c0| 74 65 72 6e 20 63 68 61 | 72 20 61 5b 5d 2e 0a 0a |tern cha|r a[]...|
|000013d0| 32 2e 32 3a 09 42 75 74 | 20 49 20 68 65 61 72 64 |2.2:.But| I heard|
|000013e0| 20 74 68 61 74 20 63 68 | 61 72 20 61 5b 5d 20 77 | that ch|ar a[] w|
|000013f0| 61 73 20 69 64 65 6e 74 | 69 63 61 6c 20 74 6f 20 |as ident|ical to |
|00001400| 63 68 61 72 20 2a 61 2e | 0a 0a 41 3a 09 4e 6f 74 |char *a.|..A:.Not|
|00001410| 20 61 74 20 61 6c 6c 2e | 20 20 41 72 72 61 79 73 | at all.| Arrays|
|00001420| 20 61 72 65 20 6e 6f 74 | 20 70 6f 69 6e 74 65 72 | are not| pointer|
|00001430| 73 2e 20 20 41 20 72 65 | 66 65 72 65 6e 63 65 20 |s. A re|ference |
|00001440| 6c 69 6b 65 20 78 5b 33 | 5d 0a 09 67 65 6e 65 72 |like x[3|]..gener|
|00001450| 61 74 65 73 20 64 69 66 | 66 65 72 65 6e 74 20 63 |ates dif|ferent c|
|00001460| 6f 64 65 20 64 65 70 65 | 6e 64 69 6e 67 20 6f 6e |ode depe|nding on|
|00001470| 20 77 68 65 74 68 65 72 | 20 78 20 69 73 20 61 6e | whether| x is an|
|00001480| 20 61 72 72 61 79 20 6f | 72 20 61 0a 09 70 6f 69 | array o|r a..poi|
|00001490| 6e 74 65 72 2e 0a 0a 32 | 2e 33 3a 09 53 6f 20 77 |nter...2|.3:.So w|
|000014a0| 68 61 74 20 69 73 20 6d | 65 61 6e 74 20 62 79 20 |hat is m|eant by |
|000014b0| 74 68 65 20 22 65 71 75 | 69 76 61 6c 65 6e 63 65 |the "equ|ivalence|
|000014c0| 20 6f 66 20 70 6f 69 6e | 74 65 72 73 20 61 6e 64 | of poin|ters and|
|000014d0| 20 61 72 72 61 79 73 22 | 20 69 6e 0a 09 43 3f 0a | arrays"| in..C?.|
|000014e0| 0a 41 3a 09 41 6e 20 6c | 76 61 6c 75 65 20 6f 66 |.A:.An l|value of|
|000014f0| 20 74 79 70 65 20 61 72 | 72 61 79 2d 6f 66 2d 54 | type ar|ray-of-T|
|00001500| 20 77 68 69 63 68 20 61 | 70 70 65 61 72 73 20 69 | which a|ppears i|
|00001510| 6e 20 61 6e 20 65 78 70 | 72 65 73 73 69 6f 6e 0a |n an exp|ression.|
|00001520| 09 64 65 63 61 79 73 20 | 69 6e 74 6f 20 61 20 70 |.decays |into a p|
|00001530| 6f 69 6e 74 65 72 20 74 | 6f 20 69 74 73 20 66 69 |ointer t|o its fi|
|00001540| 72 73 74 20 65 6c 65 6d | 65 6e 74 3b 20 74 68 65 |rst elem|ent; the|
|00001550| 20 74 79 70 65 20 6f 66 | 20 74 68 65 0a 09 72 65 | type of| the..re|
|00001560| 73 75 6c 74 61 6e 74 20 | 70 6f 69 6e 74 65 72 20 |sultant |pointer |
|00001570| 69 73 20 70 6f 69 6e 74 | 65 72 2d 74 6f 2d 54 2e |is point|er-to-T.|
|00001580| 20 20 53 6f 20 66 6f 72 | 20 61 6e 20 61 72 72 61 | So for| an arra|
|00001590| 79 20 61 20 61 6e 64 0a | 09 70 6f 69 6e 74 65 72 |y a and.|.pointer|
|000015a0| 20 70 2c 20 79 6f 75 20 | 63 61 6e 20 73 61 79 20 | p, you |can say |
|000015b0| 22 70 20 3d 20 61 3b 22 | 20 61 6e 64 20 74 68 65 |"p = a;"| and the|
|000015c0| 6e 20 70 5b 33 5d 20 61 | 6e 64 20 61 5b 33 5d 20 |n p[3] a|nd a[3] |
|000015d0| 77 69 6c 6c 0a 09 61 63 | 63 65 73 73 20 74 68 65 |will..ac|cess the|
|000015e0| 20 73 61 6d 65 20 65 6c | 65 6d 65 6e 74 2e 0a 0a | same el|ement...|
|000015f0| 32 2e 34 3a 09 57 68 79 | 20 61 72 65 20 61 72 72 |2.4:.Why| are arr|
|00001600| 61 79 20 61 6e 64 20 70 | 6f 69 6e 74 65 72 20 64 |ay and p|ointer d|
|00001610| 65 63 6c 61 72 61 74 69 | 6f 6e 73 20 69 6e 74 65 |eclarati|ons inte|
|00001620| 72 63 68 61 6e 67 65 61 | 62 6c 65 20 61 73 0a 09 |rchangea|ble as..|
|00001630| 66 75 6e 63 74 69 6f 6e | 20 66 6f 72 6d 61 6c 20 |function| formal |
|00001640| 70 61 72 61 6d 65 74 65 | 72 73 3f 0a 0a 41 3a 09 |paramete|rs?..A:.|
|00001650| 53 69 6e 63 65 20 66 75 | 6e 63 74 69 6f 6e 73 20 |Since fu|nctions |
|00001660| 63 61 6e 20 6e 65 76 65 | 72 20 72 65 63 65 69 76 |can neve|r receiv|
|00001670| 65 20 61 72 72 61 79 73 | 20 61 73 20 70 61 72 61 |e arrays| as para|
|00001680| 6d 65 74 65 72 73 2c 20 | 61 6e 79 0a 09 70 61 72 |meters, |any..par|
|00001690| 61 6d 65 74 65 72 20 64 | 65 63 6c 61 72 61 74 69 |ameter d|eclarati|
|000016a0| 6f 6e 73 20 77 68 69 63 | 68 20 22 6c 6f 6f 6b 20 |ons whic|h "look |
|000016b0| 6c 69 6b 65 22 20 61 72 | 72 61 79 73 20 61 72 65 |like" ar|rays are|
|000016c0| 20 74 72 65 61 74 65 64 | 20 62 79 0a 09 74 68 65 | treated| by..the|
|000016d0| 20 63 6f 6d 70 69 6c 65 | 72 20 61 73 20 69 66 20 | compile|r as if |
|000016e0| 74 68 65 79 20 77 65 72 | 65 20 70 6f 69 6e 74 65 |they wer|e pointe|
|000016f0| 72 73 2e 0a 0a 32 2e 35 | 3a 09 48 6f 77 20 63 61 |rs...2.5|:.How ca|
|00001700| 6e 20 61 6e 20 61 72 72 | 61 79 20 62 65 20 61 6e |n an arr|ay be an|
|00001710| 20 6c 76 61 6c 75 65 2c | 20 69 66 20 79 6f 75 20 | lvalue,| if you |
|00001720| 63 61 6e 27 74 20 61 73 | 73 69 67 6e 20 74 6f 20 |can't as|sign to |
|00001730| 69 74 3f 0a 0a 41 3a 09 | 41 6e 20 61 72 72 61 79 |it?..A:.|An array|
|00001740| 20 69 73 20 6e 6f 74 20 | 61 20 22 6d 6f 64 69 66 | is not |a "modif|
|00001750| 69 61 62 6c 65 20 6c 76 | 61 6c 75 65 2e 22 0a 0a |iable lv|alue."..|
|00001760| 32 2e 36 3a 09 57 68 79 | 20 64 6f 65 73 6e 27 74 |2.6:.Why| doesn't|
|00001770| 20 73 69 7a 65 6f 66 20 | 70 72 6f 70 65 72 6c 79 | sizeof |properly|
|00001780| 20 72 65 70 6f 72 74 20 | 74 68 65 20 73 69 7a 65 | report |the size|
|00001790| 20 6f 66 20 61 6e 20 61 | 72 72 61 79 20 77 68 69 | of an a|rray whi|
|000017a0| 63 68 20 69 73 0a 09 61 | 20 70 61 72 61 6d 65 74 |ch is..a| paramet|
|000017b0| 65 72 20 74 6f 20 61 20 | 66 75 6e 63 74 69 6f 6e |er to a |function|
|000017c0| 3f 0a 0a 41 3a 09 54 68 | 65 20 73 69 7a 65 6f 66 |?..A:.Th|e sizeof|
|000017d0| 20 6f 70 65 72 61 74 6f | 72 20 72 65 70 6f 72 74 | operato|r report|
|000017e0| 73 20 74 68 65 20 73 69 | 7a 65 20 6f 66 20 74 68 |s the si|ze of th|
|000017f0| 65 20 70 6f 69 6e 74 65 | 72 20 70 61 72 61 6d 65 |e pointe|r parame|
|00001800| 74 65 72 0a 09 77 68 69 | 63 68 20 74 68 65 20 66 |ter..whi|ch the f|
|00001810| 75 6e 63 74 69 6f 6e 20 | 61 63 74 75 61 6c 6c 79 |unction |actually|
|00001820| 20 72 65 63 65 69 76 65 | 73 2e 0a 0a 32 2e 37 3a | receive|s...2.7:|
|00001830| 09 53 6f 6d 65 6f 6e 65 | 20 65 78 70 6c 61 69 6e |.Someone| explain|
|00001840| 65 64 20 74 6f 20 6d 65 | 20 74 68 61 74 20 61 72 |ed to me| that ar|
|00001850| 72 61 79 73 20 77 65 72 | 65 20 72 65 61 6c 6c 79 |rays wer|e really|
|00001860| 20 6a 75 73 74 20 63 6f | 6e 73 74 61 6e 74 0a 09 | just co|nstant..|
|00001870| 70 6f 69 6e 74 65 72 73 | 2e 0a 0a 41 3a 09 41 6e |pointers|...A:.An|
|00001880| 20 61 72 72 61 79 20 6e | 61 6d 65 20 69 73 20 22 | array n|ame is "|
|00001890| 63 6f 6e 73 74 61 6e 74 | 22 20 69 6e 20 74 68 61 |constant|" in tha|
|000018a0| 74 20 69 74 20 63 61 6e | 6e 6f 74 20 62 65 20 61 |t it can|not be a|
|000018b0| 73 73 69 67 6e 65 64 20 | 74 6f 2c 0a 09 62 75 74 |ssigned |to,..but|
|000018c0| 20 61 6e 20 61 72 72 61 | 79 20 69 73 20 5f 6e 6f | an arra|y is _no|
|000018d0| 74 5f 20 61 20 70 6f 69 | 6e 74 65 72 2e 0a 0a 32 |t_ a poi|nter...2|
|000018e0| 2e 38 3a 09 57 68 61 74 | 20 69 73 20 74 68 65 20 |.8:.What| is the |
|000018f0| 72 65 61 6c 20 64 69 66 | 66 65 72 65 6e 63 65 20 |real dif|ference |
|00001900| 62 65 74 77 65 65 6e 20 | 61 72 72 61 79 73 20 61 |between |arrays a|
|00001910| 6e 64 20 70 6f 69 6e 74 | 65 72 73 3f 0a 0a 41 3a |nd point|ers?..A:|
|00001920| 09 41 72 72 61 79 73 20 | 61 75 74 6f 6d 61 74 69 |.Arrays |automati|
|00001930| 63 61 6c 6c 79 20 61 6c | 6c 6f 63 61 74 65 20 73 |cally al|locate s|
|00001940| 70 61 63 65 20 77 68 69 | 63 68 20 69 73 20 66 69 |pace whi|ch is fi|
|00001950| 78 65 64 20 69 6e 20 73 | 69 7a 65 20 61 6e 64 0a |xed in s|ize and.|
|00001960| 09 6c 6f 63 61 74 69 6f | 6e 3b 20 70 6f 69 6e 74 |.locatio|n; point|
|00001970| 65 72 73 20 61 72 65 20 | 64 79 6e 61 6d 69 63 2e |ers are |dynamic.|
|00001980| 0a 0a 32 2e 39 3a 09 49 | 20 63 61 6d 65 20 61 63 |..2.9:.I| came ac|
|00001990| 72 6f 73 73 20 73 6f 6d | 65 20 22 6a 6f 6b 65 22 |ross som|e "joke"|
|000019a0| 20 63 6f 64 65 20 63 6f | 6e 74 61 69 6e 69 6e 67 | code co|ntaining|
|000019b0| 20 74 68 65 20 22 65 78 | 70 72 65 73 73 69 6f 6e | the "ex|pression|
|000019c0| 22 0a 09 35 5b 22 61 62 | 63 64 65 66 22 5d 20 2e |"..5["ab|cdef"] .|
|000019d0| 20 20 48 6f 77 20 63 61 | 6e 20 74 68 69 73 20 62 | How ca|n this b|
|000019e0| 65 20 6c 65 67 61 6c 20 | 43 3f 0a 0a 41 3a 09 59 |e legal |C?..A:.Y|
|000019f0| 65 73 2c 20 61 72 72 61 | 79 20 73 75 62 73 63 72 |es, arra|y subscr|
|00001a00| 69 70 74 69 6e 67 20 69 | 73 20 63 6f 6d 6d 75 74 |ipting i|s commut|
|00001a10| 61 74 69 76 65 20 69 6e | 20 43 2e 20 20 54 68 65 |ative in| C. The|
|00001a20| 20 61 72 72 61 79 0a 09 | 73 75 62 73 63 72 69 70 | array..|subscrip|
|00001a30| 74 69 6e 67 20 6f 70 65 | 72 61 74 69 6f 6e 20 61 |ting ope|ration a|
|00001a40| 5b 65 5d 20 69 73 20 64 | 65 66 69 6e 65 64 20 61 |[e] is d|efined a|
|00001a50| 73 20 62 65 69 6e 67 20 | 69 64 65 6e 74 69 63 61 |s being |identica|
|00001a60| 6c 20 74 6f 0a 09 2a 28 | 28 61 29 2b 28 65 29 29 |l to..*(|(a)+(e))|
|00001a70| 2e 0a 0a 32 2e 31 30 3a | 09 4d 79 20 63 6f 6d 70 |...2.10:|.My comp|
|00001a80| 69 6c 65 72 20 63 6f 6d | 70 6c 61 69 6e 65 64 20 |iler com|plained |
|00001a90| 77 68 65 6e 20 49 20 70 | 61 73 73 65 64 20 61 20 |when I p|assed a |
|00001aa0| 74 77 6f 2d 64 69 6d 65 | 6e 73 69 6f 6e 61 6c 20 |two-dime|nsional |
|00001ab0| 61 72 72 61 79 20 74 6f | 0a 09 61 20 72 6f 75 74 |array to|..a rout|
|00001ac0| 69 6e 65 20 65 78 70 65 | 63 74 69 6e 67 20 61 20 |ine expe|cting a |
|00001ad0| 70 6f 69 6e 74 65 72 20 | 74 6f 20 61 20 70 6f 69 |pointer |to a poi|
|00001ae0| 6e 74 65 72 2e 0a 0a 41 | 3a 09 54 68 65 20 72 75 |nter...A|:.The ru|
|00001af0| 6c 65 20 62 79 20 77 68 | 69 63 68 20 61 72 72 61 |le by wh|ich arra|
|00001b00| 79 73 20 64 65 63 61 79 | 20 69 6e 74 6f 20 70 6f |ys decay| into po|
|00001b10| 69 6e 74 65 72 73 20 69 | 73 20 6e 6f 74 20 61 70 |inters i|s not ap|
|00001b20| 70 6c 69 65 64 0a 09 72 | 65 63 75 72 73 69 76 65 |plied..r|ecursive|
|00001b30| 6c 79 2e 20 20 41 6e 20 | 61 72 72 61 79 20 6f 66 |ly. An |array of|
|00001b40| 20 61 72 72 61 79 73 20 | 28 69 2e 65 2e 20 61 20 | arrays |(i.e. a |
|00001b50| 74 77 6f 2d 64 69 6d 65 | 6e 73 69 6f 6e 61 6c 20 |two-dime|nsional |
|00001b60| 61 72 72 61 79 0a 09 69 | 6e 20 43 29 20 64 65 63 |array..i|n C) dec|
|00001b70| 61 79 73 20 69 6e 74 6f | 20 61 20 70 6f 69 6e 74 |ays into| a point|
|00001b80| 65 72 20 74 6f 20 61 6e | 20 61 72 72 61 79 2c 20 |er to an| array, |
|00001b90| 6e 6f 74 20 61 20 70 6f | 69 6e 74 65 72 20 74 6f |not a po|inter to|
|00001ba0| 20 61 0a 09 70 6f 69 6e | 74 65 72 2e 0a 0a 32 2e | a..poin|ter...2.|
|00001bb0| 31 31 3a 09 48 6f 77 20 | 64 6f 20 49 20 77 72 69 |11:.How |do I wri|
|00001bc0| 74 65 20 66 75 6e 63 74 | 69 6f 6e 73 20 77 68 69 |te funct|ions whi|
|00001bd0| 63 68 20 61 63 63 65 70 | 74 20 32 2d 64 69 6d 65 |ch accep|t 2-dime|
|00001be0| 6e 73 69 6f 6e 61 6c 20 | 61 72 72 61 79 73 20 77 |nsional |arrays w|
|00001bf0| 68 65 6e 0a 09 74 68 65 | 20 22 77 69 64 74 68 22 |hen..the| "width"|
|00001c00| 20 69 73 20 6e 6f 74 20 | 6b 6e 6f 77 6e 20 61 74 | is not |known at|
|00001c10| 20 63 6f 6d 70 69 6c 65 | 20 74 69 6d 65 3f 0a 0a | compile| time?..|
|00001c20| 41 3a 09 49 74 27 73 20 | 6e 6f 74 20 70 61 72 74 |A:.It's |not part|
|00001c30| 69 63 75 6c 61 72 6c 79 | 20 65 61 73 79 2e 0a 0a |icularly| easy...|
|00001c40| 32 2e 31 32 3a 09 48 6f | 77 20 64 6f 20 49 20 64 |2.12:.Ho|w do I d|
|00001c50| 65 63 6c 61 72 65 20 61 | 20 70 6f 69 6e 74 65 72 |eclare a| pointer|
|00001c60| 20 74 6f 20 61 6e 20 61 | 72 72 61 79 3f 0a 0a 41 | to an a|rray?..A|
|00001c70| 3a 09 55 73 75 61 6c 6c | 79 2c 20 79 6f 75 20 64 |:.Usuall|y, you d|
|00001c80| 6f 6e 27 74 20 77 61 6e | 74 20 74 6f 2e 20 20 43 |on't wan|t to. C|
|00001c90| 6f 6e 73 69 64 65 72 20 | 75 73 69 6e 67 20 61 20 |onsider |using a |
|00001ca0| 70 6f 69 6e 74 65 72 20 | 74 6f 20 6f 6e 65 20 6f |pointer |to one o|
|00001cb0| 66 0a 09 74 68 65 20 61 | 72 72 61 79 27 73 20 65 |f..the a|rray's e|
|00001cc0| 6c 65 6d 65 6e 74 73 20 | 69 6e 73 74 65 61 64 2e |lements |instead.|
|00001cd0| 0a 0a 32 2e 31 33 3a 09 | 57 68 61 74 27 73 20 74 |..2.13:.|What's t|
|00001ce0| 68 65 20 64 69 66 66 65 | 72 65 6e 63 65 20 62 65 |he diffe|rence be|
|00001cf0| 74 77 65 65 6e 20 61 72 | 72 61 79 20 61 6e 64 20 |tween ar|ray and |
|00001d00| 26 61 72 72 61 79 3f 0a | 0a 41 3a 09 55 6e 64 65 |&array?.|.A:.Unde|
|00001d10| 72 20 41 4e 53 49 2f 49 | 53 4f 20 53 74 61 6e 64 |r ANSI/I|SO Stand|
|00001d20| 61 72 64 20 43 2c 20 26 | 61 72 72 61 79 20 79 69 |ard C, &|array yi|
|00001d30| 65 6c 64 73 20 61 20 70 | 6f 69 6e 74 65 72 20 74 |elds a p|ointer t|
|00001d40| 6f 20 74 68 65 20 65 6e | 74 69 72 65 0a 09 61 72 |o the en|tire..ar|
|00001d50| 72 61 79 2e 20 20 41 6e | 20 75 6e 61 64 6f 72 6e |ray. An| unadorn|
|00001d60| 65 64 20 72 65 66 65 72 | 65 6e 63 65 20 74 6f 20 |ed refer|ence to |
|00001d70| 61 6e 20 61 72 72 61 79 | 20 79 69 65 6c 64 73 20 |an array| yields |
|00001d80| 61 20 70 6f 69 6e 74 65 | 72 20 74 6f 0a 09 74 68 |a pointe|r to..th|
|00001d90| 65 20 61 72 72 61 79 27 | 73 20 66 69 72 73 74 20 |e array'|s first |
|00001da0| 65 6c 65 6d 65 6e 74 2e | 0a 0a 32 2e 31 34 3a 09 |element.|..2.14:.|
|00001db0| 48 6f 77 20 63 61 6e 20 | 49 20 64 79 6e 61 6d 69 |How can |I dynami|
|00001dc0| 63 61 6c 6c 79 20 61 6c | 6c 6f 63 61 74 65 20 61 |cally al|locate a|
|00001dd0| 20 6d 75 6c 74 69 64 69 | 6d 65 6e 73 69 6f 6e 61 | multidi|mensiona|
|00001de0| 6c 20 61 72 72 61 79 3f | 0a 0a 41 3a 09 49 74 20 |l array?|..A:.It |
|00001df0| 69 73 20 75 73 75 61 6c | 6c 79 20 62 65 73 74 20 |is usual|ly best |
|00001e00| 74 6f 20 61 6c 6c 6f 63 | 61 74 65 20 61 6e 20 61 |to alloc|ate an a|
|00001e10| 72 72 61 79 20 6f 66 20 | 70 6f 69 6e 74 65 72 73 |rray of |pointers|
|00001e20| 2c 20 61 6e 64 20 74 68 | 65 6e 0a 09 69 6e 69 74 |, and th|en..init|
|00001e30| 69 61 6c 69 7a 65 20 65 | 61 63 68 20 70 6f 69 6e |ialize e|ach poin|
|00001e40| 74 65 72 20 74 6f 20 61 | 20 64 79 6e 61 6d 69 63 |ter to a| dynamic|
|00001e50| 61 6c 6c 79 2d 61 6c 6c | 6f 63 61 74 65 64 20 22 |ally-all|ocated "|
|00001e60| 72 6f 77 2e 22 20 20 53 | 65 65 0a 09 74 68 65 20 |row." S|ee..the |
|00001e70| 66 75 6c 6c 20 6c 69 73 | 74 20 66 6f 72 20 63 6f |full lis|t for co|
|00001e80| 64 65 20 73 61 6d 70 6c | 65 73 2e 0a 0a 32 2e 31 |de sampl|es...2.1|
|00001e90| 35 3a 09 48 6f 77 20 63 | 61 6e 20 49 20 75 73 65 |5:.How c|an I use|
|00001ea0| 20 73 74 61 74 69 63 61 | 6c 6c 79 2d 20 61 6e 64 | statica|lly- and|
|00001eb0| 20 64 79 6e 61 6d 69 63 | 61 6c 6c 79 2d 61 6c 6c | dynamic|ally-all|
|00001ec0| 6f 63 61 74 65 64 0a 09 | 6d 75 6c 74 69 64 69 6d |ocated..|multidim|
|00001ed0| 65 6e 73 69 6f 6e 61 6c | 20 61 72 72 61 79 73 20 |ensional| arrays |
|00001ee0| 69 6e 74 65 72 63 68 61 | 6e 67 65 61 62 6c 79 20 |intercha|ngeably |
|00001ef0| 77 68 65 6e 20 70 61 73 | 73 69 6e 67 20 74 68 65 |when pas|sing the|
|00001f00| 6d 20 74 6f 0a 09 66 75 | 6e 63 74 69 6f 6e 73 3f |m to..fu|nctions?|
|00001f10| 0a 0a 41 3a 09 54 68 65 | 72 65 20 69 73 20 6e 6f |..A:.The|re is no|
|00001f20| 20 73 69 6e 67 6c 65 20 | 70 65 72 66 65 63 74 20 | single |perfect |
|00001f30| 6d 65 74 68 6f 64 2c 20 | 62 75 74 20 73 65 65 20 |method, |but see |
|00001f40| 74 68 65 20 66 75 6c 6c | 20 6c 69 73 74 20 66 6f |the full| list fo|
|00001f50| 72 0a 09 73 6f 6d 65 20 | 69 64 65 61 73 2e 0a 0a |r..some |ideas...|
|00001f60| 32 2e 31 36 3a 09 43 61 | 6e 20 49 20 73 69 6d 75 |2.16:.Ca|n I simu|
|00001f70| 6c 61 74 65 20 61 20 6e | 6f 6e 2d 30 2d 62 61 73 |late a n|on-0-bas|
|00001f80| 65 64 20 61 72 72 61 79 | 20 77 69 74 68 20 61 20 |ed array| with a |
|00001f90| 70 6f 69 6e 74 65 72 3f | 0a 0a 41 3a 09 4e 6f 74 |pointer?|..A:.Not|
|00001fa0| 20 69 66 20 74 68 65 20 | 70 6f 69 6e 74 65 72 20 | if the |pointer |
|00001fb0| 70 6f 69 6e 74 73 20 6f | 75 74 73 69 64 65 20 6f |points o|utside o|
|00001fc0| 66 20 74 68 65 20 62 6c | 6f 63 6b 20 6f 66 20 6d |f the bl|ock of m|
|00001fd0| 65 6d 6f 72 79 20 69 74 | 20 69 73 0a 09 69 6e 74 |emory it| is..int|
|00001fe0| 65 6e 64 65 64 20 74 6f | 20 61 63 63 65 73 73 2e |ended to| access.|
|00001ff0| 0a 0a 32 2e 31 37 3a 09 | 49 20 70 61 73 73 65 64 |..2.17:.|I passed|
|00002000| 20 61 20 70 6f 69 6e 74 | 65 72 20 74 6f 20 61 20 | a point|er to a |
|00002010| 66 75 6e 63 74 69 6f 6e | 20 77 68 69 63 68 20 69 |function| which i|
|00002020| 6e 69 74 69 61 6c 69 7a | 65 64 20 69 74 2c 20 62 |nitializ|ed it, b|
|00002030| 75 74 20 74 68 65 0a 09 | 70 6f 69 6e 74 65 72 20 |ut the..|pointer |
|00002040| 69 6e 20 74 68 65 20 63 | 61 6c 6c 65 72 20 77 61 |in the c|aller wa|
|00002050| 73 20 75 6e 63 68 61 6e | 67 65 64 2e 0a 0a 41 3a |s unchan|ged...A:|
|00002060| 09 54 68 65 20 63 61 6c | 6c 65 64 20 66 75 6e 63 |.The cal|led func|
|00002070| 74 69 6f 6e 20 70 72 6f | 62 61 62 6c 79 20 61 6c |tion pro|bably al|
|00002080| 74 65 72 65 64 20 6f 6e | 6c 79 20 74 68 65 20 70 |tered on|ly the p|
|00002090| 61 73 73 65 64 20 63 6f | 70 79 20 6f 66 20 74 68 |assed co|py of th|
|000020a0| 65 0a 09 70 6f 69 6e 74 | 65 72 2e 0a 0a 32 2e 31 |e..point|er...2.1|
|000020b0| 38 3a 09 49 20 68 61 76 | 65 20 61 20 63 68 61 72 |8:.I hav|e a char|
|000020c0| 20 2a 20 70 6f 69 6e 74 | 65 72 20 74 68 61 74 20 | * point|er that |
|000020d0| 68 61 70 70 65 6e 73 20 | 74 6f 20 70 6f 69 6e 74 |happens |to point|
|000020e0| 20 74 6f 20 73 6f 6d 65 | 20 69 6e 74 73 2c 20 61 | to some| ints, a|
|000020f0| 6e 64 0a 09 49 20 77 61 | 6e 74 20 74 6f 20 73 74 |nd..I wa|nt to st|
|00002100| 65 70 20 69 74 20 6f 76 | 65 72 20 74 68 65 6d 2e |ep it ov|er them.|
|00002110| 20 20 57 68 79 20 64 6f | 65 73 6e 27 74 20 22 28 | Why do|esn't "(|
|00002120| 28 69 6e 74 20 2a 29 70 | 29 2b 2b 3b 22 20 77 6f |(int *)p|)++;" wo|
|00002130| 72 6b 3f 0a 0a 41 3a 09 | 49 6e 20 43 2c 20 61 20 |rk?..A:.|In C, a |
|00002140| 63 61 73 74 20 6f 70 65 | 72 61 74 6f 72 20 69 73 |cast ope|rator is|
|00002150| 20 61 20 63 6f 6e 76 65 | 72 73 69 6f 6e 20 6f 70 | a conve|rsion op|
|00002160| 65 72 61 74 6f 72 2c 20 | 61 6e 64 20 62 79 0a 09 |erator, |and by..|
|00002170| 64 65 66 69 6e 69 74 69 | 6f 6e 20 69 74 20 79 69 |definiti|on it yi|
|00002180| 65 6c 64 73 20 61 6e 20 | 72 76 61 6c 75 65 2c 20 |elds an |rvalue, |
|00002190| 77 68 69 63 68 20 63 61 | 6e 6e 6f 74 20 62 65 20 |which ca|nnot be |
|000021a0| 61 73 73 69 67 6e 65 64 | 20 74 6f 2c 20 6f 72 0a |assigned| to, or.|
|000021b0| 09 69 6e 63 72 65 6d 65 | 6e 74 65 64 20 77 69 74 |.increme|nted wit|
|000021c0| 68 20 2b 2b 2e 0a 0a 32 | 2e 31 39 3a 09 43 61 6e |h ++...2|.19:.Can|
|000021d0| 20 49 20 75 73 65 20 61 | 20 76 6f 69 64 20 2a 2a | I use a| void **|
|000021e0| 20 70 6f 69 6e 74 65 72 | 20 74 6f 20 70 61 73 73 | pointer| to pass|
|000021f0| 20 61 20 67 65 6e 65 72 | 69 63 20 70 6f 69 6e 74 | a gener|ic point|
|00002200| 65 72 20 74 6f 20 61 0a | 09 66 75 6e 63 74 69 6f |er to a.|.functio|
|00002210| 6e 20 62 79 20 72 65 66 | 65 72 65 6e 63 65 3f 0a |n by ref|erence?.|
|00002220| 0a 41 3a 09 4e 6f 74 20 | 70 6f 72 74 61 62 6c 79 |.A:.Not |portably|
|00002230| 2e 0a 0a 0a 53 65 63 74 | 69 6f 6e 20 33 2e 20 4d |....Sect|ion 3. M|
|00002240| 65 6d 6f 72 79 20 41 6c | 6c 6f 63 61 74 69 6f 6e |emory Al|location|
|00002250| 0a 0a 33 2e 31 3a 09 57 | 68 79 20 64 6f 65 73 6e |..3.1:.W|hy doesn|
|00002260| 27 74 20 74 68 65 20 63 | 6f 64 65 20 22 63 68 61 |'t the c|ode "cha|
|00002270| 72 20 2a 61 6e 73 77 65 | 72 3b 20 67 65 74 73 28 |r *answe|r; gets(|
|00002280| 61 6e 73 77 65 72 29 3b | 22 20 77 6f 72 6b 3f 0a |answer);|" work?.|
|00002290| 0a 41 3a 09 54 68 65 20 | 70 6f 69 6e 74 65 72 20 |.A:.The |pointer |
|000022a0| 76 61 72 69 61 62 6c 65 | 20 22 61 6e 73 77 65 72 |variable| "answer|
|000022b0| 22 20 68 61 73 20 6e 6f | 74 20 62 65 65 6e 20 73 |" has no|t been s|
|000022c0| 65 74 20 74 6f 20 70 6f | 69 6e 74 20 74 6f 20 61 |et to po|int to a|
|000022d0| 6e 79 0a 09 76 61 6c 69 | 64 20 73 74 6f 72 61 67 |ny..vali|d storag|
|000022e0| 65 2e 20 20 54 68 65 20 | 73 69 6d 70 6c 65 73 74 |e. The |simplest|
|000022f0| 20 77 61 79 20 74 6f 20 | 63 6f 72 72 65 63 74 20 | way to |correct |
|00002300| 74 68 69 73 20 66 72 61 | 67 6d 65 6e 74 20 69 73 |this fra|gment is|
|00002310| 20 74 6f 0a 09 75 73 65 | 20 61 20 6c 6f 63 61 6c | to..use| a local|
|00002320| 20 61 72 72 61 79 2c 20 | 69 6e 73 74 65 61 64 20 | array, |instead |
|00002330| 6f 66 20 61 20 70 6f 69 | 6e 74 65 72 2e 0a 0a 33 |of a poi|nter...3|
|00002340| 2e 32 3a 09 49 20 63 61 | 6e 27 74 20 67 65 74 20 |.2:.I ca|n't get |
|00002350| 73 74 72 63 61 74 20 74 | 6f 20 77 6f 72 6b 2e 20 |strcat t|o work. |
|00002360| 20 49 20 74 72 69 65 64 | 20 22 63 68 61 72 20 2a | I tried| "char *|
|00002370| 73 31 20 3d 20 22 48 65 | 6c 6c 6f 2c 20 22 2c 0a |s1 = "He|llo, ",.|
|00002380| 09 2a 73 32 20 3d 20 22 | 77 6f 72 6c 64 21 22 2c |.*s2 = "|world!",|
|00002390| 20 2a 73 33 20 3d 20 73 | 74 72 63 61 74 28 73 31 | *s3 = s|trcat(s1|
|000023a0| 2c 20 73 32 29 3b 22 20 | 62 75 74 20 49 20 67 6f |, s2);" |but I go|
|000023b0| 74 20 73 74 72 61 6e 67 | 65 0a 09 72 65 73 75 6c |t strang|e..resul|
|000023c0| 74 73 2e 0a 0a 41 3a 09 | 41 67 61 69 6e 2c 20 74 |ts...A:.|Again, t|
|000023d0| 68 65 20 70 72 6f 62 6c | 65 6d 20 69 73 20 74 68 |he probl|em is th|
|000023e0| 61 74 20 73 70 61 63 65 | 20 66 6f 72 20 74 68 65 |at space| for the|
|000023f0| 20 63 6f 6e 63 61 74 65 | 6e 61 74 65 64 20 72 65 | concate|nated re|
|00002400| 73 75 6c 74 20 69 73 0a | 09 6e 6f 74 20 70 72 6f |sult is.|.not pro|
|00002410| 70 65 72 6c 79 20 61 6c | 6c 6f 63 61 74 65 64 2e |perly al|located.|
|00002420| 0a 0a 33 2e 33 3a 09 42 | 75 74 20 74 68 65 20 6d |..3.3:.B|ut the m|
|00002430| 61 6e 20 70 61 67 65 20 | 66 6f 72 20 73 74 72 63 |an page |for strc|
|00002440| 61 74 20 73 61 79 73 20 | 74 68 61 74 20 69 74 20 |at says |that it |
|00002450| 74 61 6b 65 73 20 74 77 | 6f 20 63 68 61 72 20 2a |takes tw|o char *|
|00002460| 27 73 20 61 73 0a 09 61 | 72 67 75 6d 65 6e 74 73 |'s as..a|rguments|
|00002470| 2e 20 20 48 6f 77 20 61 | 6d 20 49 20 73 75 70 70 |. How a|m I supp|
|00002480| 6f 73 65 64 20 74 6f 20 | 6b 6e 6f 77 20 74 6f 20 |osed to |know to |
|00002490| 61 6c 6c 6f 63 61 74 65 | 20 74 68 69 6e 67 73 3f |allocate| things?|
|000024a0| 0a 0a 41 3a 09 49 6e 20 | 67 65 6e 65 72 61 6c 2c |..A:.In |general,|
|000024b0| 20 77 68 65 6e 20 75 73 | 69 6e 67 20 70 6f 69 6e | when us|ing poin|
|000024c0| 74 65 72 73 20 79 6f 75 | 20 5f 61 6c 77 61 79 73 |ters you| _always|
|000024d0| 5f 20 68 61 76 65 20 74 | 6f 20 63 6f 6e 73 69 64 |_ have t|o consid|
|000024e0| 65 72 0a 09 6d 65 6d 6f | 72 79 20 61 6c 6c 6f 63 |er..memo|ry alloc|
|000024f0| 61 74 69 6f 6e 2c 20 61 | 74 20 6c 65 61 73 74 20 |ation, a|t least |
|00002500| 74 6f 20 6d 61 6b 65 20 | 73 75 72 65 20 74 68 61 |to make |sure tha|
|00002510| 74 20 74 68 65 20 63 6f | 6d 70 69 6c 65 72 20 69 |t the co|mpiler i|
|00002520| 73 0a 09 64 6f 69 6e 67 | 20 69 74 20 66 6f 72 20 |s..doing| it for |
|00002530| 79 6f 75 2e 0a 0a 33 2e | 34 3a 09 49 20 68 61 76 |you...3.|4:.I hav|
|00002540| 65 20 61 20 66 75 6e 63 | 74 69 6f 6e 20 74 68 61 |e a func|tion tha|
|00002550| 74 20 69 73 20 73 75 70 | 70 6f 73 65 64 20 74 6f |t is sup|posed to|
|00002560| 20 72 65 74 75 72 6e 20 | 61 20 73 74 72 69 6e 67 | return |a string|
|00002570| 2c 20 62 75 74 20 77 68 | 65 6e 0a 09 69 74 20 72 |, but wh|en..it r|
|00002580| 65 74 75 72 6e 73 20 74 | 6f 20 69 74 73 20 63 61 |eturns t|o its ca|
|00002590| 6c 6c 65 72 2c 20 74 68 | 65 20 72 65 74 75 72 6e |ller, th|e return|
|000025a0| 65 64 20 73 74 72 69 6e | 67 20 69 73 20 67 61 72 |ed strin|g is gar|
|000025b0| 62 61 67 65 2e 0a 0a 41 | 3a 09 4d 61 6b 65 20 73 |bage...A|:.Make s|
|000025c0| 75 72 65 20 74 68 61 74 | 20 74 68 65 20 6d 65 6d |ure that| the mem|
|000025d0| 6f 72 79 20 74 6f 20 77 | 68 69 63 68 20 74 68 65 |ory to w|hich the|
|000025e0| 20 66 75 6e 63 74 69 6f | 6e 20 72 65 74 75 72 6e | functio|n return|
|000025f0| 73 20 61 0a 09 70 6f 69 | 6e 74 65 72 20 69 73 20 |s a..poi|nter is |
|00002600| 63 6f 72 72 65 63 74 6c | 79 20 28 69 2e 65 2e 20 |correctl|y (i.e. |
|00002610| 6e 6f 74 20 6c 6f 63 61 | 6c 6c 79 29 20 61 6c 6c |not loca|lly) all|
|00002620| 6f 63 61 74 65 64 2e 0a | 0a 33 2e 35 3a 09 57 68 |ocated..|.3.5:.Wh|
|00002630| 79 20 64 6f 65 73 20 73 | 6f 6d 65 20 63 6f 64 65 |y does s|ome code|
|00002640| 20 63 61 72 65 66 75 6c | 6c 79 20 63 61 73 74 20 | careful|ly cast |
|00002650| 74 68 65 20 76 61 6c 75 | 65 73 20 72 65 74 75 72 |the valu|es retur|
|00002660| 6e 65 64 20 62 79 20 6d | 61 6c 6c 6f 63 0a 09 74 |ned by m|alloc..t|
|00002670| 6f 20 74 68 65 20 70 6f | 69 6e 74 65 72 20 74 79 |o the po|inter ty|
|00002680| 70 65 20 62 65 69 6e 67 | 20 61 6c 6c 6f 63 61 74 |pe being| allocat|
|00002690| 65 64 3f 0a 0a 41 3a 09 | 42 65 66 6f 72 65 20 41 |ed?..A:.|Before A|
|000026a0| 4e 53 49 2f 49 53 4f 20 | 43 2c 20 74 68 65 73 65 |NSI/ISO |C, these|
|000026b0| 20 63 61 73 74 73 20 77 | 65 72 65 20 72 65 71 75 | casts w|ere requ|
|000026c0| 69 72 65 64 20 74 6f 20 | 73 69 6c 65 6e 63 65 20 |ired to |silence |
|000026d0| 63 65 72 74 61 69 6e 0a | 09 77 61 72 6e 69 6e 67 |certain.|.warning|
|000026e0| 73 2e 0a 0a 33 2e 36 3a | 09 59 6f 75 20 63 61 6e |s...3.6:|.You can|
|000026f0| 27 74 20 75 73 65 20 64 | 79 6e 61 6d 69 63 61 6c |'t use d|ynamical|
|00002700| 6c 79 2d 61 6c 6c 6f 63 | 61 74 65 64 20 6d 65 6d |ly-alloc|ated mem|
|00002710| 6f 72 79 20 61 66 74 65 | 72 20 79 6f 75 20 66 72 |ory afte|r you fr|
|00002720| 65 65 20 69 74 2c 0a 09 | 63 61 6e 20 79 6f 75 3f |ee it,..|can you?|
|00002730| 0a 0a 41 3a 09 4e 6f 2e | 20 20 53 6f 6d 65 20 65 |..A:.No.| Some e|
|00002740| 61 72 6c 79 20 64 6f 63 | 75 6d 65 6e 74 61 74 69 |arly doc|umentati|
|00002750| 6f 6e 20 69 6d 70 6c 69 | 65 64 20 6f 74 68 65 72 |on impli|ed other|
|00002760| 77 69 73 65 2c 20 62 75 | 74 20 74 68 65 20 63 6c |wise, bu|t the cl|
|00002770| 61 69 6d 0a 09 69 73 20 | 6e 6f 20 6c 6f 6e 67 65 |aim..is |no longe|
|00002780| 72 20 76 61 6c 69 64 2e | 0a 0a 33 2e 37 3a 09 48 |r valid.|..3.7:.H|
|00002790| 6f 77 20 64 6f 65 73 20 | 66 72 65 65 28 29 20 6b |ow does |free() k|
|000027a0| 6e 6f 77 20 68 6f 77 20 | 6d 61 6e 79 20 62 79 74 |now how |many byt|
|000027b0| 65 73 20 74 6f 20 66 72 | 65 65 3f 0a 0a 41 3a 09 |es to fr|ee?..A:.|
|000027c0| 54 68 65 20 6d 61 6c 6c | 6f 63 2f 66 72 65 65 20 |The mall|oc/free |
|000027d0| 70 61 63 6b 61 67 65 20 | 72 65 6d 65 6d 62 65 72 |package |remember|
|000027e0| 73 20 74 68 65 20 73 69 | 7a 65 20 6f 66 20 65 61 |s the si|ze of ea|
|000027f0| 63 68 20 62 6c 6f 63 6b | 20 69 74 0a 09 61 6c 6c |ch block| it..all|
|00002800| 6f 63 61 74 65 73 20 61 | 6e 64 20 72 65 74 75 72 |ocates a|nd retur|
|00002810| 6e 73 2e 0a 0a 33 2e 38 | 3a 09 53 6f 20 63 61 6e |ns...3.8|:.So can|
|00002820| 20 49 20 71 75 65 72 79 | 20 74 68 65 20 6d 61 6c | I query| the mal|
|00002830| 6c 6f 63 20 70 61 63 6b | 61 67 65 20 74 6f 20 66 |loc pack|age to f|
|00002840| 69 6e 64 20 6f 75 74 20 | 68 6f 77 20 62 69 67 20 |ind out |how big |
|00002850| 61 6e 0a 09 61 6c 6c 6f | 63 61 74 65 64 20 62 6c |an..allo|cated bl|
|00002860| 6f 63 6b 20 69 73 3f 0a | 0a 41 3a 09 4e 6f 74 20 |ock is?.|.A:.Not |
|00002870| 70 6f 72 74 61 62 6c 79 | 2e 0a 0a 33 2e 39 3a 09 |portably|...3.9:.|
|00002880| 57 68 65 6e 20 49 20 66 | 72 65 65 20 61 20 64 79 |When I f|ree a dy|
|00002890| 6e 61 6d 69 63 61 6c 6c | 79 2d 61 6c 6c 6f 63 61 |namicall|y-alloca|
|000028a0| 74 65 64 20 73 74 72 75 | 63 74 75 72 65 20 63 6f |ted stru|cture co|
|000028b0| 6e 74 61 69 6e 69 6e 67 | 0a 09 70 6f 69 6e 74 65 |ntaining|..pointe|
|000028c0| 72 73 2c 20 64 6f 20 49 | 20 68 61 76 65 20 74 6f |rs, do I| have to|
|000028d0| 20 66 72 65 65 20 65 61 | 63 68 20 73 75 62 73 69 | free ea|ch subsi|
|000028e0| 64 69 61 72 79 20 70 6f | 69 6e 74 65 72 20 66 69 |diary po|inter fi|
|000028f0| 72 73 74 3f 0a 0a 41 3a | 09 59 65 73 2e 0a 0a 33 |rst?..A:|.Yes...3|
|00002900| 2e 31 30 3a 09 57 68 79 | 20 64 6f 65 73 6e 27 74 |.10:.Why| doesn't|
|00002910| 20 6d 79 20 70 72 6f 67 | 72 61 6d 27 73 20 6d 65 | my prog|ram's me|
|00002920| 6d 6f 72 79 20 75 73 61 | 67 65 20 67 6f 20 64 6f |mory usa|ge go do|
|00002930| 77 6e 20 77 68 65 6e 20 | 49 20 66 72 65 65 0a 09 |wn when |I free..|
|00002940| 6d 65 6d 6f 72 79 3f 0a | 0a 41 3a 09 4d 6f 73 74 |memory?.|.A:.Most|
|00002950| 20 69 6d 70 6c 65 6d 65 | 6e 74 61 74 69 6f 6e 73 | impleme|ntations|
|00002960| 20 6f 66 20 6d 61 6c 6c | 6f 63 2f 66 72 65 65 20 | of mall|oc/free |
|00002970| 64 6f 20 6e 6f 74 20 72 | 65 74 75 72 6e 20 66 72 |do not r|eturn fr|
|00002980| 65 65 64 20 6d 65 6d 6f | 72 79 0a 09 74 6f 20 74 |eed memo|ry..to t|
|00002990| 68 65 20 6f 70 65 72 61 | 74 69 6e 67 20 73 79 73 |he opera|ting sys|
|000029a0| 74 65 6d 2e 0a 0a 33 2e | 31 31 3a 09 4d 75 73 74 |tem...3.|11:.Must|
|000029b0| 20 49 20 66 72 65 65 20 | 61 6c 6c 6f 63 61 74 65 | I free |allocate|
|000029c0| 64 20 6d 65 6d 6f 72 79 | 20 62 65 66 6f 72 65 20 |d memory| before |
|000029d0| 74 68 65 20 70 72 6f 67 | 72 61 6d 20 65 78 69 74 |the prog|ram exit|
|000029e0| 73 3f 0a 0a 41 3a 09 59 | 6f 75 20 73 68 6f 75 6c |s?..A:.Y|ou shoul|
|000029f0| 64 6e 27 74 20 68 61 76 | 65 20 74 6f 2e 0a 0a 33 |dn't hav|e to...3|
|00002a00| 2e 31 32 3a 09 49 73 20 | 69 74 20 6c 65 67 61 6c |.12:.Is |it legal|
|00002a10| 20 74 6f 20 70 61 73 73 | 20 61 20 6e 75 6c 6c 20 | to pass| a null |
|00002a20| 70 6f 69 6e 74 65 72 20 | 61 73 20 74 68 65 20 66 |pointer |as the f|
|00002a30| 69 72 73 74 20 61 72 67 | 75 6d 65 6e 74 20 74 6f |irst arg|ument to|
|00002a40| 0a 09 72 65 61 6c 6c 6f | 63 28 29 3f 0a 0a 41 3a |..reallo|c()?..A:|
|00002a50| 09 41 4e 53 49 20 43 20 | 73 61 6e 63 74 69 6f 6e |.ANSI C |sanction|
|00002a60| 73 20 74 68 69 73 20 75 | 73 61 67 65 2c 20 62 75 |s this u|sage, bu|
|00002a70| 74 20 73 65 76 65 72 61 | 6c 20 65 61 72 6c 69 65 |t severa|l earlie|
|00002a80| 72 20 69 6d 70 6c 65 6d | 65 6e 74 61 74 69 6f 6e |r implem|entation|
|00002a90| 73 0a 09 64 6f 20 6e 6f | 74 20 73 75 70 70 6f 72 |s..do no|t suppor|
|00002aa0| 74 20 69 74 2e 0a 0a 33 | 2e 31 33 3a 09 49 73 20 |t it...3|.13:.Is |
|00002ab0| 69 74 20 73 61 66 65 20 | 74 6f 20 75 73 65 20 63 |it safe |to use c|
|00002ac0| 61 6c 6c 6f 63 27 73 20 | 7a 65 72 6f 2d 66 69 6c |alloc's |zero-fil|
|00002ad0| 6c 20 67 75 61 72 61 6e | 74 65 65 20 66 6f 72 20 |l guaran|tee for |
|00002ae0| 70 6f 69 6e 74 65 72 20 | 61 6e 64 0a 09 66 6c 6f |pointer |and..flo|
|00002af0| 61 74 69 6e 67 2d 70 6f | 69 6e 74 20 76 61 6c 75 |ating-po|int valu|
|00002b00| 65 73 3f 0a 0a 41 3a 09 | 4e 6f 2e 0a 0a 33 2e 31 |es?..A:.|No...3.1|
|00002b10| 34 3a 09 57 68 61 74 20 | 69 73 20 61 6c 6c 6f 63 |4:.What |is alloc|
|00002b20| 61 20 61 6e 64 20 77 68 | 79 20 69 73 20 69 74 73 |a and wh|y is its|
|00002b30| 20 75 73 65 20 64 69 73 | 63 6f 75 72 61 67 65 64 | use dis|couraged|
|00002b40| 3f 0a 0a 41 3a 09 61 6c | 6c 6f 63 61 20 61 6c 6c |?..A:.al|loca all|
|00002b50| 6f 63 61 74 65 73 20 6d | 65 6d 6f 72 79 20 77 68 |ocates m|emory wh|
|00002b60| 69 63 68 20 69 73 20 61 | 75 74 6f 6d 61 74 69 63 |ich is a|utomatic|
|00002b70| 61 6c 6c 79 20 66 72 65 | 65 64 20 77 68 65 6e 20 |ally fre|ed when |
|00002b80| 74 68 65 0a 09 66 75 6e | 63 74 69 6f 6e 20 77 68 |the..fun|ction wh|
|00002b90| 69 63 68 20 63 61 6c 6c | 65 64 20 61 6c 6c 6f 63 |ich call|ed alloc|
|00002ba0| 61 20 72 65 74 75 72 6e | 73 2e 20 20 61 6c 6c 6f |a return|s. allo|
|00002bb0| 63 61 20 63 61 6e 6e 6f | 74 20 62 65 20 77 72 69 |ca canno|t be wri|
|00002bc0| 74 74 65 6e 0a 09 70 6f | 72 74 61 62 6c 79 2c 20 |tten..po|rtably, |
|00002bd0| 69 73 20 64 69 66 66 69 | 63 75 6c 74 20 74 6f 20 |is diffi|cult to |
|00002be0| 69 6d 70 6c 65 6d 65 6e | 74 20 6f 6e 20 6d 61 63 |implemen|t on mac|
|00002bf0| 68 69 6e 65 73 20 77 69 | 74 68 6f 75 74 20 61 20 |hines wi|thout a |
|00002c00| 73 74 61 63 6b 2c 0a 09 | 61 6e 64 20 66 61 69 6c |stack,..|and fail|
|00002c10| 73 20 75 6e 64 65 72 20 | 63 65 72 74 61 69 6e 20 |s under |certain |
|00002c20| 63 6f 6e 64 69 74 69 6f | 6e 73 20 69 66 20 69 6d |conditio|ns if im|
|00002c30| 70 6c 65 6d 65 6e 74 65 | 64 20 73 69 6d 70 6c 79 |plemente|d simply|
|00002c40| 2e 0a 0a 0a 53 65 63 74 | 69 6f 6e 20 34 2e 20 45 |....Sect|ion 4. E|
|00002c50| 78 70 72 65 73 73 69 6f | 6e 73 0a 0a 34 2e 31 3a |xpressio|ns..4.1:|
|00002c60| 09 57 68 79 20 64 6f 65 | 73 6e 27 74 20 74 68 65 |.Why doe|sn't the|
|00002c70| 20 63 6f 64 65 20 22 61 | 5b 69 5d 20 3d 20 69 2b | code "a|[i] = i+|
|00002c80| 2b 3b 22 20 77 6f 72 6b | 3f 0a 0a 41 3a 09 54 68 |+;" work|?..A:.Th|
|00002c90| 65 20 76 61 72 69 61 62 | 6c 65 20 69 20 69 73 20 |e variab|le i is |
|00002ca0| 62 6f 74 68 20 72 65 66 | 65 72 65 6e 63 65 64 20 |both ref|erenced |
|00002cb0| 61 6e 64 20 6d 6f 64 69 | 66 69 65 64 20 69 6e 20 |and modi|fied in |
|00002cc0| 74 68 65 20 73 61 6d 65 | 0a 09 65 78 70 72 65 73 |the same|..expres|
|00002cd0| 73 69 6f 6e 2e 0a 0a 34 | 2e 32 3a 09 55 6e 64 65 |sion...4|.2:.Unde|
|00002ce0| 72 20 6d 79 20 63 6f 6d | 70 69 6c 65 72 2c 20 74 |r my com|piler, t|
|00002cf0| 68 65 20 63 6f 64 65 20 | 22 69 6e 74 20 69 20 3d |he code |"int i =|
|00002d00| 20 37 3b 0a 09 70 72 69 | 6e 74 66 28 22 25 64 5c | 7;..pri|ntf("%d\|
|00002d10| 6e 22 2c 20 69 2b 2b 20 | 2a 20 69 2b 2b 29 3b 22 |n", i++ |* i++);"|
|00002d20| 20 70 72 69 6e 74 73 20 | 34 39 2e 20 20 52 65 67 | prints |49. Reg|
|00002d30| 61 72 64 6c 65 73 73 20 | 6f 66 20 74 68 65 20 6f |ardless |of the o|
|00002d40| 72 64 65 72 0a 09 6f 66 | 20 65 76 61 6c 75 61 74 |rder..of| evaluat|
|00002d50| 69 6f 6e 2c 20 73 68 6f | 75 6c 64 6e 27 74 20 69 |ion, sho|uldn't i|
|00002d60| 74 20 70 72 69 6e 74 20 | 35 36 3f 0a 0a 41 3a 09 |t print |56?..A:.|
|00002d70| 54 68 65 20 6f 70 65 72 | 61 74 69 6f 6e 73 20 69 |The oper|ations i|
|00002d80| 6d 70 6c 69 65 64 20 62 | 79 20 74 68 65 20 70 6f |mplied b|y the po|
|00002d90| 73 74 69 6e 63 72 65 6d | 65 6e 74 20 61 6e 64 20 |stincrem|ent and |
|00002da0| 70 6f 73 74 64 65 63 72 | 65 6d 65 6e 74 0a 09 6f |postdecr|ement..o|
|00002db0| 70 65 72 61 74 6f 72 73 | 20 2b 2b 20 61 6e 64 20 |perators| ++ and |
|00002dc0| 2d 2d 20 61 72 65 20 70 | 65 72 66 6f 72 6d 65 64 |-- are p|erformed|
|00002dd0| 20 61 74 20 73 6f 6d 65 | 20 74 69 6d 65 20 61 66 | at some| time af|
|00002de0| 74 65 72 20 74 68 65 0a | 09 6f 70 65 72 61 6e 64 |ter the.|.operand|
|00002df0| 27 73 20 66 6f 72 6d 65 | 72 20 76 61 6c 75 65 73 |'s forme|r values|
|00002e00| 20 61 72 65 20 79 69 65 | 6c 64 65 64 20 61 6e 64 | are yie|lded and|
|00002e10| 20 62 65 66 6f 72 65 20 | 74 68 65 20 65 6e 64 20 | before |the end |
|00002e20| 6f 66 20 74 68 65 0a 09 | 65 78 70 72 65 73 73 69 |of the..|expressi|
|00002e30| 6f 6e 2c 20 62 75 74 20 | 6e 6f 74 20 6e 65 63 65 |on, but |not nece|
|00002e40| 73 73 61 72 69 6c 79 20 | 69 6d 6d 65 64 69 61 74 |ssarily |immediat|
|00002e50| 65 6c 79 20 61 66 74 65 | 72 2c 20 6f 72 20 62 65 |ely afte|r, or be|
|00002e60| 66 6f 72 65 0a 09 6f 74 | 68 65 72 20 70 61 72 74 |fore..ot|her part|
|00002e70| 73 20 6f 66 20 74 68 65 | 20 65 78 70 72 65 73 73 |s of the| express|
|00002e80| 69 6f 6e 20 61 72 65 20 | 65 76 61 6c 75 61 74 65 |ion are |evaluate|
|00002e90| 64 2e 0a 0a 34 2e 33 3a | 09 48 6f 77 20 63 6f 75 |d...4.3:|.How cou|
|00002ea0| 6c 64 20 74 68 65 20 63 | 6f 64 65 20 22 69 6e 74 |ld the c|ode "int|
|00002eb0| 20 69 20 3d 20 32 3b 20 | 69 20 3d 20 69 2b 2b 3b | i = 2; |i = i++;|
|00002ec0| 22 20 65 76 65 72 20 67 | 69 76 65 20 34 3f 0a 0a |" ever g|ive 4?..|
|00002ed0| 41 3a 09 55 6e 64 65 66 | 69 6e 65 64 20 62 65 68 |A:.Undef|ined beh|
|00002ee0| 61 76 69 6f 72 20 6d 65 | 61 6e 73 20 5f 61 6e 79 |avior me|ans _any|
|00002ef0| 74 68 69 6e 67 5f 20 63 | 61 6e 20 68 61 70 70 65 |thing_ c|an happe|
|00002f00| 6e 2e 0a 0a 34 2e 34 3a | 09 49 20 6a 75 73 74 20 |n...4.4:|.I just |
|00002f10| 74 72 69 65 64 20 73 6f | 6d 65 20 61 6c 6c 65 67 |tried so|me alleg|
|00002f20| 65 64 6c 79 2d 75 6e 64 | 65 66 69 6e 65 64 20 63 |edly-und|efined c|
|00002f30| 6f 64 65 20 6f 6e 20 61 | 6e 20 41 4e 53 49 2d 63 |ode on a|n ANSI-c|
|00002f40| 6f 6e 66 6f 72 6d 69 6e | 67 0a 09 63 6f 6d 70 69 |onformin|g..compi|
|00002f50| 6c 65 72 2c 20 61 6e 64 | 20 67 6f 74 20 74 68 65 |ler, and| got the|
|00002f60| 20 72 65 73 75 6c 74 73 | 20 49 20 65 78 70 65 63 | results| I expec|
|00002f70| 74 65 64 2e 0a 0a 41 3a | 09 41 20 63 6f 6d 70 69 |ted...A:|.A compi|
|00002f80| 6c 65 72 20 6d 61 79 20 | 64 6f 20 61 6e 79 74 68 |ler may |do anyth|
|00002f90| 69 6e 67 20 69 74 20 6c | 69 6b 65 73 20 77 68 65 |ing it l|ikes whe|
|00002fa0| 6e 20 66 61 63 65 64 20 | 77 69 74 68 20 75 6e 64 |n faced |with und|
|00002fb0| 65 66 69 6e 65 64 0a 09 | 62 65 68 61 76 69 6f 72 |efined..|behavior|
|00002fc0| 2c 20 69 6e 63 6c 75 64 | 69 6e 67 20 64 6f 69 6e |, includ|ing doin|
|00002fd0| 67 20 77 68 61 74 20 79 | 6f 75 20 65 78 70 65 63 |g what y|ou expec|
|00002fe0| 74 2e 0a 0a 34 2e 35 3a | 09 44 6f 6e 27 74 20 70 |t...4.5:|.Don't p|
|00002ff0| 72 65 63 65 64 65 6e 63 | 65 20 61 6e 64 20 70 61 |recedenc|e and pa|
|00003000| 72 65 6e 74 68 65 73 65 | 73 20 64 69 63 74 61 74 |renthese|s dictat|
|00003010| 65 20 6f 72 64 65 72 20 | 6f 66 20 65 76 61 6c 75 |e order |of evalu|
|00003020| 61 74 69 6f 6e 3f 0a 0a | 41 3a 09 4f 70 65 72 61 |ation?..|A:.Opera|
|00003030| 74 6f 72 20 70 72 65 63 | 65 64 65 6e 63 65 20 61 |tor prec|edence a|
|00003040| 6e 64 20 65 78 70 6c 69 | 63 69 74 20 70 61 72 65 |nd expli|cit pare|
|00003050| 6e 74 68 65 73 65 73 20 | 69 6d 70 6f 73 65 20 6f |ntheses |impose o|
|00003060| 6e 6c 79 20 61 0a 09 70 | 61 72 74 69 61 6c 20 6f |nly a..p|artial o|
|00003070| 72 64 65 72 69 6e 67 20 | 6f 6e 20 74 68 65 20 65 |rdering |on the e|
|00003080| 76 61 6c 75 61 74 69 6f | 6e 20 6f 66 20 61 6e 20 |valuatio|n of an |
|00003090| 65 78 70 72 65 73 73 69 | 6f 6e 2c 20 77 68 69 63 |expressi|on, whic|
|000030a0| 68 20 64 6f 65 73 0a 09 | 6e 6f 74 20 67 65 6e 65 |h does..|not gene|
|000030b0| 72 61 6c 6c 79 20 69 6e | 63 6c 75 64 65 20 74 68 |rally in|clude th|
|000030c0| 65 20 6f 72 64 65 72 20 | 6f 66 20 73 69 64 65 20 |e order |of side |
|000030d0| 65 66 66 65 63 74 73 2e | 0a 0a 34 2e 36 3a 09 42 |effects.|..4.6:.B|
|000030e0| 75 74 20 77 68 61 74 20 | 61 62 6f 75 74 20 74 68 |ut what |about th|
|000030f0| 65 20 26 26 2c 20 7c 7c | 2c 20 61 6e 64 20 63 6f |e &&, |||, and co|
|00003100| 6d 6d 61 20 6f 70 65 72 | 61 74 6f 72 73 3f 0a 0a |mma oper|ators?..|
|00003110| 41 3a 09 54 68 65 72 65 | 20 69 73 20 61 20 73 70 |A:.There| is a sp|
|00003120| 65 63 69 61 6c 20 65 78 | 63 65 70 74 69 6f 6e 20 |ecial ex|ception |
|00003130| 66 6f 72 20 74 68 6f 73 | 65 20 6f 70 65 72 61 74 |for thos|e operat|
|00003140| 6f 72 73 2c 20 28 61 73 | 20 77 65 6c 6c 20 61 73 |ors, (as| well as|
|00003150| 0a 09 74 68 65 20 3f 3a | 20 6f 70 65 72 61 74 6f |..the ?:| operato|
|00003160| 72 29 3b 20 6c 65 66 74 | 2d 74 6f 2d 72 69 67 68 |r); left|-to-righ|
|00003170| 74 20 65 76 61 6c 75 61 | 74 69 6f 6e 20 69 73 20 |t evalua|tion is |
|00003180| 67 75 61 72 61 6e 74 65 | 65 64 2e 0a 0a 34 2e 37 |guarante|ed...4.7|
|00003190| 3a 09 49 66 20 49 27 6d | 20 6e 6f 74 20 75 73 69 |:.If I'm| not usi|
|000031a0| 6e 67 20 74 68 65 20 76 | 61 6c 75 65 20 6f 66 20 |ng the v|alue of |
|000031b0| 74 68 65 20 65 78 70 72 | 65 73 73 69 6f 6e 2c 20 |the expr|ession, |
|000031c0| 73 68 6f 75 6c 64 20 49 | 20 75 73 65 20 69 2b 2b |should I| use i++|
|000031d0| 0a 09 6f 72 20 2b 2b 69 | 20 74 6f 20 69 6e 63 72 |..or ++i| to incr|
|000031e0| 65 6d 65 6e 74 20 61 20 | 76 61 72 69 61 62 6c 65 |ement a |variable|
|000031f0| 3f 0a 0a 41 3a 09 53 69 | 6e 63 65 20 74 68 65 20 |?..A:.Si|nce the |
|00003200| 74 77 6f 20 66 6f 72 6d | 73 20 64 69 66 66 65 72 |two form|s differ|
|00003210| 20 6f 6e 6c 79 20 69 6e | 20 74 68 65 20 76 61 6c | only in| the val|
|00003220| 75 65 20 79 69 65 6c 64 | 65 64 2c 20 74 68 65 79 |ue yield|ed, they|
|00003230| 20 61 72 65 0a 09 65 6e | 74 69 72 65 6c 79 20 65 | are..en|tirely e|
|00003240| 71 75 69 76 61 6c 65 6e | 74 20 77 68 65 6e 20 6f |quivalen|t when o|
|00003250| 6e 6c 79 20 74 68 65 69 | 72 20 73 69 64 65 20 65 |nly thei|r side e|
|00003260| 66 66 65 63 74 20 69 73 | 20 6e 65 65 64 65 64 2e |ffect is| needed.|
|00003270| 0a 0a 34 2e 38 3a 09 57 | 68 79 20 64 6f 65 73 6e |..4.8:.W|hy doesn|
|00003280| 27 74 20 74 68 65 20 63 | 6f 64 65 20 22 69 6e 74 |'t the c|ode "int|
|00003290| 20 61 20 3d 20 31 30 30 | 30 2c 20 62 20 3d 20 31 | a = 100|0, b = 1|
|000032a0| 30 30 30 3b 0a 09 6c 6f | 6e 67 20 69 6e 74 20 63 |000;..lo|ng int c|
|000032b0| 20 3d 20 61 20 2a 20 62 | 3b 22 20 77 6f 72 6b 3f | = a * b|;" work?|
|000032c0| 0a 0a 41 3a 09 59 6f 75 | 20 6d 75 73 74 20 6d 61 |..A:.You| must ma|
|000032d0| 6e 75 61 6c 6c 79 20 63 | 61 73 74 20 6f 6e 65 20 |nually c|ast one |
|000032e0| 6f 66 20 74 68 65 20 6f | 70 65 72 61 6e 64 73 20 |of the o|perands |
|000032f0| 74 6f 20 28 6c 6f 6e 67 | 29 2e 0a 0a 0a 53 65 63 |to (long|)....Sec|
|00003300| 74 69 6f 6e 20 35 2e 20 | 41 4e 53 49 20 43 0a 0a |tion 5. |ANSI C..|
|00003310| 35 2e 31 3a 09 57 68 61 | 74 20 69 73 20 74 68 65 |5.1:.Wha|t is the|
|00003320| 20 22 41 4e 53 49 20 43 | 20 53 74 61 6e 64 61 72 | "ANSI C| Standar|
|00003330| 64 3f 22 0a 0a 41 3a 09 | 49 6e 20 31 39 38 33 2c |d?"..A:.|In 1983,|
|00003340| 20 74 68 65 20 41 6d 65 | 72 69 63 61 6e 20 4e 61 | the Ame|rican Na|
|00003350| 74 69 6f 6e 61 6c 20 53 | 74 61 6e 64 61 72 64 73 |tional S|tandards|
|00003360| 20 49 6e 73 74 69 74 75 | 74 65 20 28 41 4e 53 49 | Institu|te (ANSI|
|00003370| 29 0a 09 63 6f 6d 6d 69 | 73 73 69 6f 6e 65 64 20 |)..commi|ssioned |
|00003380| 61 20 63 6f 6d 6d 69 74 | 74 65 65 20 74 6f 20 73 |a commit|tee to s|
|00003390| 74 61 6e 64 61 72 64 69 | 7a 65 20 74 68 65 20 43 |tandardi|ze the C|
|000033a0| 20 6c 61 6e 67 75 61 67 | 65 2e 20 20 54 68 65 69 | languag|e. Thei|
|000033b0| 72 0a 09 77 6f 72 6b 20 | 77 61 73 20 72 61 74 69 |r..work |was rati|
|000033c0| 66 69 65 64 20 61 73 20 | 41 4e 53 20 58 33 2e 31 |fied as |ANS X3.1|
|000033d0| 35 39 2d 31 39 38 39 2c | 20 61 6e 64 20 68 61 73 |59-1989,| and has|
|000033e0| 20 73 69 6e 63 65 20 62 | 65 65 6e 20 61 64 6f 70 | since b|een adop|
|000033f0| 74 65 64 0a 09 61 73 20 | 49 53 4f 2f 49 45 43 20 |ted..as |ISO/IEC |
|00003400| 39 38 39 39 3a 31 39 39 | 30 2e 0a 0a 35 2e 32 3a |9899:199|0...5.2:|
|00003410| 09 48 6f 77 20 63 61 6e | 20 49 20 67 65 74 20 61 |.How can| I get a|
|00003420| 20 63 6f 70 79 20 6f 66 | 20 74 68 65 20 53 74 61 | copy of| the Sta|
|00003430| 6e 64 61 72 64 3f 0a 0a | 41 3a 09 41 4e 53 49 20 |ndard?..|A:.ANSI |
|00003440| 58 33 2e 31 35 39 20 68 | 61 73 20 62 65 65 6e 20 |X3.159 h|as been |
|00003450| 6f 66 66 69 63 69 61 6c | 6c 79 20 73 75 70 65 72 |official|ly super|
|00003460| 73 65 64 65 64 20 62 79 | 20 49 53 4f 20 39 38 39 |seded by| ISO 989|
|00003470| 39 2e 20 20 43 6f 70 69 | 65 73 0a 09 61 72 65 20 |9. Copi|es..are |
|00003480| 61 76 61 69 6c 61 62 6c | 65 20 66 72 6f 6d 20 41 |availabl|e from A|
|00003490| 4e 53 49 20 69 6e 20 4e | 65 77 20 59 6f 72 6b 2c |NSI in N|ew York,|
|000034a0| 20 6f 72 20 66 72 6f 6d | 20 47 6c 6f 62 61 6c 20 | or from| Global |
|000034b0| 45 6e 67 69 6e 65 65 72 | 69 6e 67 0a 09 44 6f 63 |Engineer|ing..Doc|
|000034c0| 75 6d 65 6e 74 73 20 69 | 6e 20 49 72 76 69 6e 65 |uments i|n Irvine|
|000034d0| 2c 20 43 41 2e 20 20 53 | 65 65 20 74 68 65 20 75 |, CA. S|ee the u|
|000034e0| 6e 61 62 72 69 64 67 65 | 64 20 6c 69 73 74 20 66 |nabridge|d list f|
|000034f0| 6f 72 20 61 64 64 72 65 | 73 73 65 73 2e 0a 0a 35 |or addre|sses...5|
|00003500| 2e 33 3a 09 44 6f 65 73 | 20 61 6e 79 6f 6e 65 20 |.3:.Does| anyone |
|00003510| 68 61 76 65 20 61 20 74 | 6f 6f 6c 20 66 6f 72 20 |have a t|ool for |
|00003520| 63 6f 6e 76 65 72 74 69 | 6e 67 20 6f 6c 64 2d 73 |converti|ng old-s|
|00003530| 74 79 6c 65 20 43 20 70 | 72 6f 67 72 61 6d 73 20 |tyle C p|rograms |
|00003540| 74 6f 0a 09 41 4e 53 49 | 20 43 2c 20 6f 72 20 66 |to..ANSI| C, or f|
|00003550| 6f 72 20 61 75 74 6f 6d | 61 74 69 63 61 6c 6c 79 |or autom|atically|
|00003560| 20 67 65 6e 65 72 61 74 | 69 6e 67 20 70 72 6f 74 | generat|ing prot|
|00003570| 6f 74 79 70 65 73 3f 0a | 0a 41 3a 09 53 65 65 20 |otypes?.|.A:.See |
|00003580| 74 68 65 20 66 75 6c 6c | 20 6c 69 73 74 20 66 6f |the full| list fo|
|00003590| 72 20 64 65 74 61 69 6c | 73 2e 0a 0a 35 2e 34 3a |r detail|s...5.4:|
|000035a0| 09 48 6f 77 20 64 6f 20 | 49 20 6b 65 65 70 20 74 |.How do |I keep t|
|000035b0| 68 65 20 41 4e 53 49 20 | 22 73 74 72 69 6e 67 69 |he ANSI |"stringi|
|000035c0| 7a 69 6e 67 22 20 70 72 | 65 70 72 6f 63 65 73 73 |zing" pr|eprocess|
|000035d0| 69 6e 67 20 6f 70 65 72 | 61 74 6f 72 20 66 72 6f |ing oper|ator fro|
|000035e0| 6d 0a 09 73 74 72 69 6e | 67 69 7a 69 6e 67 20 74 |m..strin|gizing t|
|000035f0| 68 65 20 6d 61 63 72 6f | 27 73 20 6e 61 6d 65 20 |he macro|'s name |
|00003600| 72 61 74 68 65 72 20 74 | 68 61 6e 20 69 74 73 20 |rather t|han its |
|00003610| 76 61 6c 75 65 3f 0a 0a | 41 3a 09 59 6f 75 20 6d |value?..|A:.You m|
|00003620| 75 73 74 20 75 73 65 20 | 61 20 74 77 6f 2d 73 74 |ust use |a two-st|
|00003630| 65 70 20 23 64 65 66 69 | 6e 69 74 69 6f 6e 20 74 |ep #defi|nition t|
|00003640| 6f 20 66 6f 72 63 65 20 | 74 68 65 20 6d 61 63 72 |o force |the macr|
|00003650| 6f 20 74 6f 20 62 65 0a | 09 65 78 70 61 6e 64 65 |o to be.|.expande|
|00003660| 64 20 61 73 20 77 65 6c | 6c 20 61 73 20 73 74 72 |d as wel|l as str|
|00003670| 69 6e 67 69 7a 65 64 2e | 0a 0a 35 2e 35 3a 09 57 |ingized.|..5.5:.W|
|00003680| 68 79 20 63 61 6e 27 74 | 20 49 20 75 73 65 20 63 |hy can't| I use c|
|00003690| 6f 6e 73 74 20 76 61 6c | 75 65 73 20 69 6e 20 69 |onst val|ues in i|
|000036a0| 6e 69 74 69 61 6c 69 7a | 65 72 73 20 61 6e 64 20 |nitializ|ers and |
|000036b0| 61 72 72 61 79 0a 09 64 | 69 6d 65 6e 73 69 6f 6e |array..d|imension|
|000036c0| 73 3f 0a 0a 41 3a 09 54 | 68 65 20 76 61 6c 75 65 |s?..A:.T|he value|
|000036d0| 20 6f 66 20 61 20 63 6f | 6e 73 74 2d 71 75 61 6c | of a co|nst-qual|
|000036e0| 69 66 69 65 64 20 6f 62 | 6a 65 63 74 20 69 73 20 |ified ob|ject is |
|000036f0| 5f 6e 6f 74 5f 20 61 20 | 63 6f 6e 73 74 61 6e 74 |_not_ a |constant|
|00003700| 0a 09 65 78 70 72 65 73 | 73 69 6f 6e 20 69 6e 20 |..expres|sion in |
|00003710| 74 68 65 20 66 75 6c 6c | 20 73 65 6e 73 65 20 6f |the full| sense o|
|00003720| 66 20 74 68 65 20 74 65 | 72 6d 2e 0a 0a 35 2e 36 |f the te|rm...5.6|
|00003730| 3a 09 57 68 61 74 27 73 | 20 74 68 65 20 64 69 66 |:.What's| the dif|
|00003740| 66 65 72 65 6e 63 65 20 | 62 65 74 77 65 65 6e 20 |ference |between |
|00003750| 22 63 68 61 72 20 63 6f | 6e 73 74 20 2a 70 22 20 |"char co|nst *p" |
|00003760| 61 6e 64 0a 09 22 63 68 | 61 72 20 2a 20 63 6f 6e |and.."ch|ar * con|
|00003770| 73 74 20 70 22 3f 0a 0a | 41 3a 09 54 68 65 20 66 |st p"?..|A:.The f|
|00003780| 6f 72 6d 65 72 20 69 73 | 20 61 20 70 6f 69 6e 74 |ormer is| a point|
|00003790| 65 72 20 74 6f 20 61 20 | 63 6f 6e 73 74 61 6e 74 |er to a |constant|
|000037a0| 20 63 68 61 72 61 63 74 | 65 72 3b 20 74 68 65 20 | charact|er; the |
|000037b0| 6c 61 74 74 65 72 20 69 | 73 20 61 0a 09 63 6f 6e |latter i|s a..con|
|000037c0| 73 74 61 6e 74 20 70 6f | 69 6e 74 65 72 20 74 6f |stant po|inter to|
|000037d0| 20 61 20 63 68 61 72 61 | 63 74 65 72 2e 0a 0a 35 | a chara|cter...5|
|000037e0| 2e 37 3a 09 57 68 79 20 | 63 61 6e 27 74 20 49 20 |.7:.Why |can't I |
|000037f0| 70 61 73 73 20 61 20 63 | 68 61 72 20 2a 2a 20 74 |pass a c|har ** t|
|00003800| 6f 20 61 20 66 75 6e 63 | 74 69 6f 6e 20 77 68 69 |o a func|tion whi|
|00003810| 63 68 20 65 78 70 65 63 | 74 73 20 61 0a 09 63 6f |ch expec|ts a..co|
|00003820| 6e 73 74 20 63 68 61 72 | 20 2a 2a 3f 0a 0a 41 3a |nst char| **?..A:|
|00003830| 09 54 68 65 20 72 75 6c | 65 20 77 68 69 63 68 20 |.The rul|e which |
|00003840| 70 65 72 6d 69 74 73 20 | 73 6c 69 67 68 74 20 6d |permits |slight m|
|00003850| 69 73 6d 61 74 63 68 65 | 73 20 69 6e 20 71 75 61 |ismatche|s in qua|
|00003860| 6c 69 66 69 65 64 20 70 | 6f 69 6e 74 65 72 0a 09 |lified p|ointer..|
|00003870| 61 73 73 69 67 6e 6d 65 | 6e 74 73 20 69 73 20 6e |assignme|nts is n|
|00003880| 6f 74 20 61 70 70 6c 69 | 65 64 20 72 65 63 75 72 |ot appli|ed recur|
|00003890| 73 69 76 65 6c 79 2e 0a | 0a 35 2e 38 3a 09 4d 79 |sively..|.5.8:.My|
|000038a0| 20 41 4e 53 49 20 63 6f | 6d 70 69 6c 65 72 20 63 | ANSI co|mpiler c|
|000038b0| 6f 6d 70 6c 61 69 6e 73 | 20 61 62 6f 75 74 20 61 |omplains| about a|
|000038c0| 20 6d 69 73 6d 61 74 63 | 68 20 77 68 65 6e 20 69 | mismatc|h when i|
|000038d0| 74 20 73 65 65 73 0a 0a | 09 09 65 78 74 65 72 6e |t sees..|..extern|
|000038e0| 20 69 6e 74 20 66 75 6e | 63 28 66 6c 6f 61 74 29 | int fun|c(float)|
|000038f0| 3b 0a 0a 09 09 69 6e 74 | 20 66 75 6e 63 28 78 29 |;....int| func(x)|
|00003900| 0a 09 09 66 6c 6f 61 74 | 20 78 3b 0a 09 09 7b 2e |...float| x;...{.|
|00003910| 2e 2e 0a 0a 41 3a 09 59 | 6f 75 20 68 61 76 65 20 |....A:.Y|ou have |
|00003920| 6d 69 78 65 64 20 74 68 | 65 20 6e 65 77 2d 73 74 |mixed th|e new-st|
|00003930| 79 6c 65 20 70 72 6f 74 | 6f 74 79 70 65 20 64 65 |yle prot|otype de|
|00003940| 63 6c 61 72 61 74 69 6f | 6e 0a 09 22 65 78 74 65 |claratio|n.."exte|
|00003950| 72 6e 20 69 6e 74 20 66 | 75 6e 63 28 66 6c 6f 61 |rn int f|unc(floa|
|00003960| 74 29 3b 22 20 77 69 74 | 68 20 74 68 65 20 6f 6c |t);" wit|h the ol|
|00003970| 64 2d 73 74 79 6c 65 20 | 64 65 66 69 6e 69 74 69 |d-style |definiti|
|00003980| 6f 6e 0a 09 22 69 6e 74 | 20 66 75 6e 63 28 78 29 |on.."int| func(x)|
|00003990| 20 66 6c 6f 61 74 20 78 | 3b 22 2e 20 20 22 4e 61 | float x|;". "Na|
|000039a0| 72 72 6f 77 22 20 74 79 | 70 65 73 20 61 72 65 20 |rrow" ty|pes are |
|000039b0| 74 72 65 61 74 65 64 20 | 64 69 66 66 65 72 65 6e |treated |differen|
|000039c0| 74 6c 79 0a 09 61 63 63 | 6f 72 64 69 6e 67 20 74 |tly..acc|ording t|
|000039d0| 6f 20 77 68 69 63 68 20 | 73 79 6e 74 61 78 20 69 |o which |syntax i|
|000039e0| 73 20 75 73 65 64 2e 20 | 20 54 68 69 73 20 70 72 |s used. | This pr|
|000039f0| 6f 62 6c 65 6d 20 63 61 | 6e 20 62 65 20 66 69 78 |oblem ca|n be fix|
|00003a00| 65 64 20 62 79 0a 09 61 | 76 6f 69 64 69 6e 67 20 |ed by..a|voiding |
|00003a10| 6e 61 72 72 6f 77 20 74 | 79 70 65 73 2c 20 6f 72 |narrow t|ypes, or|
|00003a20| 20 62 79 20 75 73 69 6e | 67 20 65 69 74 68 65 72 | by usin|g either|
|00003a30| 20 6e 65 77 2d 73 74 79 | 6c 65 20 28 70 72 6f 74 | new-sty|le (prot|
|00003a40| 6f 74 79 70 65 29 0a 09 | 6f 72 20 6f 6c 64 2d 73 |otype)..|or old-s|
|00003a50| 74 79 6c 65 20 73 79 6e | 74 61 78 20 63 6f 6e 73 |tyle syn|tax cons|
|00003a60| 69 73 74 65 6e 74 6c 79 | 2e 0a 0a 35 2e 39 3a 09 |istently|...5.9:.|
|00003a70| 43 61 6e 20 79 6f 75 20 | 6d 69 78 20 6f 6c 64 2d |Can you |mix old-|
|00003a80| 73 74 79 6c 65 20 61 6e | 64 20 6e 65 77 2d 73 74 |style an|d new-st|
|00003a90| 79 6c 65 20 66 75 6e 63 | 74 69 6f 6e 20 73 79 6e |yle func|tion syn|
|00003aa0| 74 61 78 3f 0a 0a 41 3a | 09 44 6f 69 6e 67 20 73 |tax?..A:|.Doing s|
|00003ab0| 6f 20 69 73 20 63 75 72 | 72 65 6e 74 6c 79 20 70 |o is cur|rently p|
|00003ac0| 65 72 66 65 63 74 6c 79 | 20 6c 65 67 61 6c 2e 0a |erfectly| legal..|
|00003ad0| 0a 35 2e 31 30 3a 09 57 | 68 79 20 64 6f 65 73 20 |.5.10:.W|hy does |
|00003ae0| 74 68 65 20 64 65 63 6c | 61 72 61 74 69 6f 6e 20 |the decl|aration |
|00003af0| 22 65 78 74 65 72 6e 20 | 66 28 73 74 72 75 63 74 |"extern |f(struct|
|00003b00| 20 78 20 7b 69 6e 74 20 | 73 3b 7d 20 2a 70 29 3b | x {int |s;} *p);|
|00003b10| 22 20 67 69 76 65 0a 09 | 6d 65 20 61 20 77 61 72 |" give..|me a war|
|00003b20| 6e 69 6e 67 20 6d 65 73 | 73 61 67 65 3f 0a 0a 41 |ning mes|sage?..A|
|00003b30| 3a 09 41 20 73 74 72 75 | 63 74 20 64 65 63 6c 61 |:.A stru|ct decla|
|00003b40| 72 65 64 20 6f 6e 6c 79 | 20 77 69 74 68 69 6e 20 |red only| within |
|00003b50| 61 20 70 72 6f 74 6f 74 | 79 70 65 20 63 61 6e 6e |a protot|ype cann|
|00003b60| 6f 74 20 62 65 20 63 6f | 6d 70 61 74 69 62 6c 65 |ot be co|mpatible|
|00003b70| 0a 09 77 69 74 68 20 6f | 74 68 65 72 20 73 74 72 |..with o|ther str|
|00003b80| 75 63 74 73 20 64 65 63 | 6c 61 72 65 64 20 69 6e |ucts dec|lared in|
|00003b90| 20 74 68 65 20 73 61 6d | 65 20 73 6f 75 72 63 65 | the sam|e source|
|00003ba0| 20 66 69 6c 65 2e 0a 0a | 35 2e 31 31 3a 09 49 27 | file...|5.11:.I'|
|00003bb0| 6d 20 67 65 74 74 69 6e | 67 20 73 74 72 61 6e 67 |m gettin|g strang|
|00003bc0| 65 20 73 79 6e 74 61 78 | 20 65 72 72 6f 72 73 20 |e syntax| errors |
|00003bd0| 69 6e 73 69 64 65 20 63 | 6f 64 65 20 77 68 69 63 |inside c|ode whic|
|00003be0| 68 20 49 27 76 65 0a 09 | 23 69 66 64 65 66 66 65 |h I've..|#ifdeffe|
|00003bf0| 64 20 6f 75 74 2e 0a 0a | 41 3a 09 55 6e 64 65 72 |d out...|A:.Under|
|00003c00| 20 41 4e 53 49 20 43 2c | 20 23 69 66 64 65 66 66 | ANSI C,| #ifdeff|
|00003c10| 65 64 2d 6f 75 74 20 74 | 65 78 74 20 6d 75 73 74 |ed-out t|ext must|
|00003c20| 20 73 74 69 6c 6c 20 63 | 6f 6e 73 69 73 74 20 6f | still c|onsist o|
|00003c30| 66 20 22 76 61 6c 69 64 | 0a 09 70 72 65 70 72 6f |f "valid|..prepro|
|00003c40| 63 65 73 73 69 6e 67 20 | 74 6f 6b 65 6e 73 2e 22 |cessing |tokens."|
|00003c50| 20 20 54 68 69 73 20 6d | 65 61 6e 73 20 74 68 61 | This m|eans tha|
|00003c60| 74 20 74 68 65 72 65 20 | 6d 75 73 74 20 62 65 20 |t there |must be |
|00003c70| 6e 6f 0a 09 75 6e 74 65 | 72 6d 69 6e 61 74 65 64 |no..unte|rminated|
|00003c80| 20 63 6f 6d 6d 65 6e 74 | 73 20 6f 72 20 71 75 6f | comment|s or quo|
|00003c90| 74 65 73 20 28 69 2e 65 | 2e 20 6e 6f 20 73 69 6e |tes (i.e|. no sin|
|00003ca0| 67 6c 65 20 61 70 6f 73 | 74 72 6f 70 68 65 73 29 |gle apos|trophes)|
|00003cb0| 2c 0a 09 61 6e 64 20 6e | 6f 20 6e 65 77 6c 69 6e |,..and n|o newlin|
|00003cc0| 65 73 20 69 6e 73 69 64 | 65 20 71 75 6f 74 65 73 |es insid|e quotes|
|00003cd0| 2e 0a 0a 35 2e 31 32 3a | 09 43 61 6e 20 49 20 64 |...5.12:|.Can I d|
|00003ce0| 65 63 6c 61 72 65 20 6d | 61 69 6e 20 61 73 20 76 |eclare m|ain as v|
|00003cf0| 6f 69 64 2c 20 74 6f 20 | 73 68 75 74 20 6f 66 66 |oid, to |shut off|
|00003d00| 20 74 68 65 73 65 20 61 | 6e 6e 6f 79 69 6e 67 20 | these a|nnoying |
|00003d10| 22 6d 61 69 6e 0a 09 72 | 65 74 75 72 6e 73 20 6e |"main..r|eturns n|
|00003d20| 6f 20 76 61 6c 75 65 22 | 20 6d 65 73 73 61 67 65 |o value"| message|
|00003d30| 73 3f 0a 0a 41 3a 09 4e | 6f 2e 0a 0a 35 2e 31 33 |s?..A:.N|o...5.13|
|00003d40| 3a 09 49 73 20 65 78 69 | 74 28 73 74 61 74 75 73 |:.Is exi|t(status|
|00003d50| 29 20 74 72 75 6c 79 20 | 65 71 75 69 76 61 6c 65 |) truly |equivale|
|00003d60| 6e 74 20 74 6f 20 72 65 | 74 75 72 6e 69 6e 67 20 |nt to re|turning |
|00003d70| 73 74 61 74 75 73 20 66 | 72 6f 6d 20 6d 61 69 6e |status f|rom main|
|00003d80| 3f 0a 0a 41 3a 09 46 6f | 72 6d 61 6c 6c 79 2c 20 |?..A:.Fo|rmally, |
|00003d90| 79 65 73 2e 0a 0a 35 2e | 31 34 3a 09 57 68 79 20 |yes...5.|14:.Why |
|00003da0| 64 6f 65 73 20 74 68 65 | 20 41 4e 53 49 20 53 74 |does the| ANSI St|
|00003db0| 61 6e 64 61 72 64 20 6e | 6f 74 20 67 75 61 72 61 |andard n|ot guara|
|00003dc0| 6e 74 65 65 20 6d 6f 72 | 65 20 74 68 61 6e 20 73 |ntee mor|e than s|
|00003dd0| 69 78 20 6d 6f 6e 6f 63 | 61 73 65 0a 09 63 68 61 |ix monoc|ase..cha|
|00003de0| 72 61 63 74 65 72 73 20 | 6f 66 20 65 78 74 65 72 |racters |of exter|
|00003df0| 6e 61 6c 20 69 64 65 6e | 74 69 66 69 65 72 20 73 |nal iden|tifier s|
|00003e00| 69 67 6e 69 66 69 63 61 | 6e 63 65 3f 0a 0a 41 3a |ignifica|nce?..A:|
|00003e10| 09 54 68 65 20 70 72 6f | 62 6c 65 6d 20 69 73 20 |.The pro|blem is |
|00003e20| 6f 6c 64 65 72 20 6c 69 | 6e 6b 65 72 73 20 77 68 |older li|nkers wh|
|00003e30| 69 63 68 20 63 61 6e 6e | 6f 74 20 62 65 20 66 6f |ich cann|ot be fo|
|00003e40| 72 63 65 64 20 28 62 79 | 20 6d 65 72 65 0a 09 77 |rced (by| mere..w|
|00003e50| 6f 72 64 73 20 69 6e 20 | 61 20 53 74 61 6e 64 61 |ords in |a Standa|
|00003e60| 72 64 29 20 74 6f 20 75 | 70 67 72 61 64 65 2e 0a |rd) to u|pgrade..|
|00003e70| 0a 35 2e 31 35 3a 09 57 | 68 61 74 20 69 73 20 74 |.5.15:.W|hat is t|
|00003e80| 68 65 20 64 69 66 66 65 | 72 65 6e 63 65 20 62 65 |he diffe|rence be|
|00003e90| 74 77 65 65 6e 20 6d 65 | 6d 63 70 79 20 61 6e 64 |tween me|mcpy and|
|00003ea0| 20 6d 65 6d 6d 6f 76 65 | 3f 0a 0a 41 3a 09 6d 65 | memmove|?..A:.me|
|00003eb0| 6d 6d 6f 76 65 20 6f 66 | 66 65 72 73 20 67 75 61 |mmove of|fers gua|
|00003ec0| 72 61 6e 74 65 65 64 20 | 62 65 68 61 76 69 6f 72 |ranteed |behavior|
|00003ed0| 20 69 66 20 74 68 65 20 | 73 6f 75 72 63 65 20 61 | if the |source a|
|00003ee0| 6e 64 20 64 65 73 74 69 | 6e 61 74 69 6f 6e 0a 09 |nd desti|nation..|
|00003ef0| 61 72 67 75 6d 65 6e 74 | 73 20 6f 76 65 72 6c 61 |argument|s overla|
|00003f00| 70 2e 0a 0a 35 2e 31 36 | 3a 09 4d 79 20 63 6f 6d |p...5.16|:.My com|
|00003f10| 70 69 6c 65 72 20 69 73 | 20 72 65 6a 65 63 74 69 |piler is| rejecti|
|00003f20| 6e 67 20 74 68 65 20 73 | 69 6d 70 6c 65 73 74 20 |ng the s|implest |
|00003f30| 70 6f 73 73 69 62 6c 65 | 20 74 65 73 74 20 70 72 |possible| test pr|
|00003f40| 6f 67 72 61 6d 73 2c 0a | 09 77 69 74 68 20 61 6c |ograms,.|.with al|
|00003f50| 6c 20 6b 69 6e 64 73 20 | 6f 66 20 73 79 6e 74 61 |l kinds |of synta|
|00003f60| 78 20 65 72 72 6f 72 73 | 2e 0a 0a 41 3a 09 50 65 |x errors|...A:.Pe|
|00003f70| 72 68 61 70 73 20 69 74 | 20 69 73 20 61 20 70 72 |rhaps it| is a pr|
|00003f80| 65 2d 41 4e 53 49 20 63 | 6f 6d 70 69 6c 65 72 2e |e-ANSI c|ompiler.|
|00003f90| 0a 0a 35 2e 31 37 3a 09 | 57 68 79 20 61 72 65 20 |..5.17:.|Why are |
|00003fa0| 73 6f 6d 65 20 41 4e 53 | 49 2f 49 53 4f 20 53 74 |some ANS|I/ISO St|
|00003fb0| 61 6e 64 61 72 64 20 6c | 69 62 72 61 72 79 20 72 |andard l|ibrary r|
|00003fc0| 6f 75 74 69 6e 65 73 20 | 73 68 6f 77 69 6e 67 20 |outines |showing |
|00003fd0| 75 70 20 61 73 0a 09 75 | 6e 64 65 66 69 6e 65 64 |up as..u|ndefined|
|00003fe0| 2c 20 65 76 65 6e 20 74 | 68 6f 75 67 68 20 49 27 |, even t|hough I'|
|00003ff0| 76 65 20 67 6f 74 20 61 | 6e 20 41 4e 53 49 20 63 |ve got a|n ANSI c|
|00004000| 6f 6d 70 69 6c 65 72 3f | 0a 0a 41 3a 09 50 65 72 |ompiler?|..A:.Per|
|00004010| 68 61 70 73 20 79 6f 75 | 20 64 6f 6e 27 74 20 68 |haps you| don't h|
|00004020| 61 76 65 20 41 4e 53 49 | 2d 63 6f 6d 70 61 74 69 |ave ANSI|-compati|
|00004030| 62 6c 65 20 68 65 61 64 | 65 72 73 20 61 6e 64 20 |ble head|ers and |
|00004040| 6c 69 62 72 61 72 69 65 | 73 2e 0a 0a 35 2e 31 38 |librarie|s...5.18|
|00004050| 3a 09 57 68 79 20 77 6f | 6e 27 74 20 66 72 6f 62 |:.Why wo|n't frob|
|00004060| 6f 7a 7a 2d 63 63 2c 20 | 77 68 69 63 68 20 63 6c |ozz-cc, |which cl|
|00004070| 61 69 6d 73 20 74 6f 20 | 62 65 20 41 4e 53 49 20 |aims to |be ANSI |
|00004080| 63 6f 6d 70 6c 69 61 6e | 74 2c 20 61 63 63 65 70 |complian|t, accep|
|00004090| 74 0a 09 74 68 69 73 20 | 63 6f 64 65 3f 0a 0a 41 |t..this |code?..A|
|000040a0| 3a 09 41 72 65 20 79 6f | 75 20 73 75 72 65 20 74 |:.Are yo|u sure t|
|000040b0| 68 61 74 20 74 68 65 20 | 63 6f 64 65 20 62 65 69 |hat the |code bei|
|000040c0| 6e 67 20 72 65 6a 65 63 | 74 65 64 20 64 6f 65 73 |ng rejec|ted does|
|000040d0| 6e 27 74 20 72 65 6c 79 | 20 6f 6e 20 73 6f 6d 65 |n't rely| on some|
|000040e0| 0a 09 6e 6f 6e 2d 53 74 | 61 6e 64 61 72 64 20 65 |..non-St|andard e|
|000040f0| 78 74 65 6e 73 69 6f 6e | 3f 0a 0a 35 2e 31 39 3a |xtension|?..5.19:|
|00004100| 09 57 68 79 20 63 61 6e | 27 74 20 49 20 70 65 72 |.Why can|'t I per|
|00004110| 66 6f 72 6d 20 61 72 69 | 74 68 6d 65 74 69 63 20 |form ari|thmetic |
|00004120| 6f 6e 20 61 20 76 6f 69 | 64 20 2a 20 70 6f 69 6e |on a voi|d * poin|
|00004130| 74 65 72 3f 0a 0a 41 3a | 09 54 68 65 20 63 6f 6d |ter?..A:|.The com|
|00004140| 70 69 6c 65 72 20 64 6f | 65 73 6e 27 74 20 6b 6e |piler do|esn't kn|
|00004150| 6f 77 20 74 68 65 20 73 | 69 7a 65 20 6f 66 20 74 |ow the s|ize of t|
|00004160| 68 65 20 70 6f 69 6e 74 | 65 64 2d 74 6f 20 6f 62 |he point|ed-to ob|
|00004170| 6a 65 63 74 73 2e 0a 0a | 35 2e 32 30 3a 09 49 73 |jects...|5.20:.Is|
|00004180| 20 63 68 61 72 20 61 5b | 33 5d 20 3d 20 22 61 62 | char a[|3] = "ab|
|00004190| 63 22 3b 20 6c 65 67 61 | 6c 3f 0a 0a 41 3a 09 59 |c"; lega|l?..A:.Y|
|000041a0| 65 73 2c 20 69 6e 20 41 | 4e 53 49 20 43 2e 0a 0a |es, in A|NSI C...|
|000041b0| 35 2e 32 31 3a 09 57 68 | 61 74 20 61 72 65 20 23 |5.21:.Wh|at are #|
|000041c0| 70 72 61 67 6d 61 73 20 | 61 6e 64 20 77 68 61 74 |pragmas |and what|
|000041d0| 20 61 72 65 20 74 68 65 | 79 20 67 6f 6f 64 20 66 | are the|y good f|
|000041e0| 6f 72 3f 0a 0a 41 3a 09 | 54 68 65 20 23 70 72 61 |or?..A:.|The #pra|
|000041f0| 67 6d 61 20 64 69 72 65 | 63 74 69 76 65 20 70 72 |gma dire|ctive pr|
|00004200| 6f 76 69 64 65 73 20 61 | 20 73 69 6e 67 6c 65 2c |ovides a| single,|
|00004210| 20 77 65 6c 6c 2d 64 65 | 66 69 6e 65 64 20 22 65 | well-de|fined "e|
|00004220| 73 63 61 70 65 0a 09 68 | 61 74 63 68 22 20 77 68 |scape..h|atch" wh|
|00004230| 69 63 68 20 63 61 6e 20 | 62 65 20 75 73 65 64 20 |ich can |be used |
|00004240| 66 6f 72 20 65 78 74 65 | 6e 73 69 6f 6e 73 2e 0a |for exte|nsions..|
|00004250| 0a 35 2e 32 32 3a 09 57 | 68 61 74 20 64 6f 65 73 |.5.22:.W|hat does|
|00004260| 20 22 23 70 72 61 67 6d | 61 20 6f 6e 63 65 22 20 | "#pragm|a once" |
|00004270| 6d 65 61 6e 3f 0a 0a 41 | 3a 09 49 74 20 69 73 20 |mean?..A|:.It is |
|00004280| 61 6e 20 65 78 74 65 6e | 73 69 6f 6e 20 69 6d 70 |an exten|sion imp|
|00004290| 6c 65 6d 65 6e 74 65 64 | 20 62 79 20 73 6f 6d 65 |lemented| by some|
|000042a0| 20 70 72 65 70 72 6f 63 | 65 73 73 6f 72 73 20 74 | preproc|essors t|
|000042b0| 6f 20 68 65 6c 70 0a 09 | 6d 61 6b 65 20 68 65 61 |o help..|make hea|
|000042c0| 64 65 72 20 66 69 6c 65 | 73 20 69 64 65 6d 70 6f |der file|s idempo|
|000042d0| 74 65 6e 74 2e 0a 0a 35 | 2e 32 33 3a 09 57 68 61 |tent...5|.23:.Wha|
|000042e0| 74 27 73 20 74 68 65 20 | 64 69 66 66 65 72 65 6e |t's the |differen|
|000042f0| 63 65 20 62 65 74 77 65 | 65 6e 20 69 6d 70 6c 65 |ce betwe|en imple|
|00004300| 6d 65 6e 74 61 74 69 6f | 6e 2d 64 65 66 69 6e 65 |mentatio|n-define|
|00004310| 64 2c 0a 09 75 6e 73 70 | 65 63 69 66 69 65 64 2c |d,..unsp|ecified,|
|00004320| 20 61 6e 64 20 75 6e 64 | 65 66 69 6e 65 64 20 62 | and und|efined b|
|00004330| 65 68 61 76 69 6f 72 3f | 0a 0a 41 3a 09 49 66 20 |ehavior?|..A:.If |
|00004340| 79 6f 75 27 72 65 20 77 | 72 69 74 69 6e 67 20 70 |you're w|riting p|
|00004350| 6f 72 74 61 62 6c 65 20 | 63 6f 64 65 2c 20 69 67 |ortable |code, ig|
|00004360| 6e 6f 72 65 20 74 68 65 | 20 64 69 73 74 69 6e 63 |nore the| distinc|
|00004370| 74 69 6f 6e 73 2e 0a 09 | 4f 74 68 65 72 77 69 73 |tions...|Otherwis|
|00004380| 65 2c 20 73 65 65 20 74 | 68 65 20 66 75 6c 6c 20 |e, see t|he full |
|00004390| 6c 69 73 74 2e 0a 0a 0a | 53 65 63 74 69 6f 6e 20 |list....|Section |
|000043a0| 36 2e 20 43 20 50 72 65 | 70 72 6f 63 65 73 73 6f |6. C Pre|processo|
|000043b0| 72 0a 0a 36 2e 31 3a 09 | 48 6f 77 20 63 61 6e 20 |r..6.1:.|How can |
|000043c0| 49 20 77 72 69 74 65 20 | 61 20 67 65 6e 65 72 69 |I write |a generi|
|000043d0| 63 20 6d 61 63 72 6f 20 | 74 6f 20 73 77 61 70 20 |c macro |to swap |
|000043e0| 74 77 6f 20 76 61 6c 75 | 65 73 3f 0a 0a 41 3a 09 |two valu|es?..A:.|
|000043f0| 54 68 65 72 65 20 69 73 | 20 6e 6f 20 67 6f 6f 64 |There is| no good|
|00004400| 20 61 6e 73 77 65 72 20 | 74 6f 20 74 68 69 73 20 | answer |to this |
|00004410| 71 75 65 73 74 69 6f 6e | 2e 20 20 54 68 65 20 62 |question|. The b|
|00004420| 65 73 74 20 61 6c 6c 2d | 61 72 6f 75 6e 64 0a 09 |est all-|around..|
|00004430| 73 6f 6c 75 74 69 6f 6e | 20 69 73 20 70 72 6f 62 |solution| is prob|
|00004440| 61 62 6c 79 20 74 6f 20 | 66 6f 72 67 65 74 20 61 |ably to |forget a|
|00004450| 62 6f 75 74 20 75 73 69 | 6e 67 20 61 20 6d 61 63 |bout usi|ng a mac|
|00004460| 72 6f 2e 0a 0a 36 2e 32 | 3a 09 49 20 68 61 76 65 |ro...6.2|:.I have|
|00004470| 20 73 6f 6d 65 20 6f 6c | 64 20 63 6f 64 65 20 74 | some ol|d code t|
|00004480| 68 61 74 20 74 72 69 65 | 73 20 74 6f 20 63 6f 6e |hat trie|s to con|
|00004490| 73 74 72 75 63 74 20 69 | 64 65 6e 74 69 66 69 65 |struct i|dentifie|
|000044a0| 72 73 20 77 69 74 68 20 | 61 0a 09 6d 61 63 72 6f |rs with |a..macro|
|000044b0| 20 6c 69 6b 65 20 22 23 | 64 65 66 69 6e 65 20 50 | like "#|define P|
|000044c0| 61 73 74 65 28 61 2c 20 | 62 29 20 61 2f 2a 2a 2f |aste(a, |b) a/**/|
|000044d0| 62 20 22 2c 20 62 75 74 | 20 69 74 20 64 6f 65 73 |b ", but| it does|
|000044e0| 6e 27 74 20 77 6f 72 6b | 0a 09 61 6e 79 20 6d 6f |n't work|..any mo|
|000044f0| 72 65 2e 0a 0a 41 3a 09 | 54 72 79 20 74 68 65 20 |re...A:.|Try the |
|00004500| 41 4e 53 49 20 74 6f 6b | 65 6e 2d 70 61 73 74 69 |ANSI tok|en-pasti|
|00004510| 6e 67 20 6f 70 65 72 61 | 74 6f 72 20 23 23 2e 0a |ng opera|tor ##..|
|00004520| 0a 36 2e 33 3a 09 57 68 | 61 74 27 73 20 74 68 65 |.6.3:.Wh|at's the|
|00004530| 20 62 65 73 74 20 77 61 | 79 20 74 6f 20 77 72 69 | best wa|y to wri|
|00004540| 74 65 20 61 20 6d 75 6c | 74 69 2d 73 74 61 74 65 |te a mul|ti-state|
|00004550| 6d 65 6e 74 20 63 70 70 | 20 6d 61 63 72 6f 3f 0a |ment cpp| macro?.|
|00004560| 0a 41 3a 09 23 64 65 66 | 69 6e 65 20 46 75 6e 63 |.A:.#def|ine Func|
|00004570| 28 29 20 64 6f 20 7b 73 | 74 6d 74 31 3b 20 73 74 |() do {s|tmt1; st|
|00004580| 6d 74 32 3b 20 2e 2e 2e | 20 7d 20 77 68 69 6c 65 |mt2; ...| } while|
|00004590| 28 30 29 20 20 2f 2a 20 | 28 6e 6f 20 74 72 61 69 |(0) /* |(no trai|
|000045a0| 6c 69 6e 67 20 3b 29 20 | 2a 2f 0a 0a 36 2e 34 3a |ling ;) |*/..6.4:|
|000045b0| 09 49 73 20 69 74 20 61 | 63 63 65 70 74 61 62 6c |.Is it a|cceptabl|
|000045c0| 65 20 66 6f 72 20 6f 6e | 65 20 68 65 61 64 65 72 |e for on|e header|
|000045d0| 20 66 69 6c 65 20 74 6f | 20 23 69 6e 63 6c 75 64 | file to| #includ|
|000045e0| 65 20 61 6e 6f 74 68 65 | 72 3f 0a 0a 41 3a 09 49 |e anothe|r?..A:.I|
|000045f0| 74 27 73 20 61 20 71 75 | 65 73 74 69 6f 6e 20 6f |t's a qu|estion o|
|00004600| 66 20 73 74 79 6c 65 2c | 20 61 6e 64 20 74 68 75 |f style,| and thu|
|00004610| 73 20 72 65 63 65 69 76 | 65 73 20 63 6f 6e 73 69 |s receiv|es consi|
|00004620| 64 65 72 61 62 6c 65 20 | 64 65 62 61 74 65 2e 0a |derable |debate..|
|00004630| 0a 36 2e 35 3a 09 44 6f | 65 73 20 74 68 65 20 73 |.6.5:.Do|es the s|
|00004640| 69 7a 65 6f 66 20 6f 70 | 65 72 61 74 6f 72 20 77 |izeof op|erator w|
|00004650| 6f 72 6b 20 69 6e 20 70 | 72 65 70 72 6f 63 65 73 |ork in p|reproces|
|00004660| 73 6f 72 20 23 69 66 20 | 64 69 72 65 63 74 69 76 |sor #if |directiv|
|00004670| 65 73 3f 0a 0a 41 3a 09 | 4e 6f 2e 0a 0a 36 2e 36 |es?..A:.|No...6.6|
|00004680| 3a 09 48 6f 77 20 63 61 | 6e 20 49 20 75 73 65 20 |:.How ca|n I use |
|00004690| 61 20 70 72 65 70 72 6f | 63 65 73 73 6f 72 20 23 |a prepro|cessor #|
|000046a0| 69 66 20 65 78 70 72 65 | 73 73 69 6f 6e 20 74 6f |if expre|ssion to|
|000046b0| 20 64 65 74 65 63 74 0a | 09 65 6e 64 69 61 6e 6e | detect.|.endiann|
|000046c0| 65 73 73 3f 0a 0a 41 3a | 09 59 6f 75 20 70 72 6f |ess?..A:|.You pro|
|000046d0| 62 61 62 6c 79 20 63 61 | 6e 27 74 2e 0a 0a 36 2e |bably ca|n't...6.|
|000046e0| 37 3a 09 49 27 76 65 20 | 67 6f 74 20 74 68 69 73 |7:.I've |got this|
|000046f0| 20 74 72 69 63 6b 79 20 | 70 72 6f 63 65 73 73 69 | tricky |processi|
|00004700| 6e 67 20 49 20 77 61 6e | 74 20 74 6f 20 64 6f 20 |ng I wan|t to do |
|00004710| 61 74 20 63 6f 6d 70 69 | 6c 65 20 74 69 6d 65 20 |at compi|le time |
|00004720| 61 6e 64 0a 09 49 20 63 | 61 6e 27 74 20 66 69 67 |and..I c|an't fig|
|00004730| 75 72 65 20 6f 75 74 20 | 61 20 77 61 79 20 74 6f |ure out |a way to|
|00004740| 20 67 65 74 20 63 70 70 | 20 74 6f 20 64 6f 20 69 | get cpp| to do i|
|00004750| 74 2e 0a 0a 41 3a 09 43 | 6f 6e 73 69 64 65 72 20 |t...A:.C|onsider |
|00004760| 77 72 69 74 69 6e 67 20 | 79 6f 75 72 20 6f 77 6e |writing |your own|
|00004770| 20 6c 69 74 74 6c 65 20 | 73 70 65 63 69 61 6c 2d | little |special-|
|00004780| 70 75 72 70 6f 73 65 20 | 70 72 65 70 72 6f 63 65 |purpose |preproce|
|00004790| 73 73 69 6e 67 0a 09 74 | 6f 6f 6c 2c 20 69 6e 73 |ssing..t|ool, ins|
|000047a0| 74 65 61 64 2e 0a 0a 36 | 2e 38 3a 09 48 6f 77 20 |tead...6|.8:.How |
|000047b0| 63 61 6e 20 49 20 70 72 | 65 70 72 6f 63 65 73 73 |can I pr|eprocess|
|000047c0| 20 73 6f 6d 65 20 63 6f | 64 65 20 74 6f 20 72 65 | some co|de to re|
|000047d0| 6d 6f 76 65 20 73 65 6c | 65 63 74 65 64 20 63 6f |move sel|ected co|
|000047e0| 6e 64 69 74 69 6f 6e 61 | 6c 0a 09 63 6f 6d 70 69 |nditiona|l..compi|
|000047f0| 6c 61 74 69 6f 6e 73 2c | 20 77 69 74 68 6f 75 74 |lations,| without|
|00004800| 20 70 72 65 70 72 6f 63 | 65 73 73 69 6e 67 20 65 | preproc|essing e|
|00004810| 76 65 72 79 74 68 69 6e | 67 3f 0a 0a 41 3a 09 4c |verythin|g?..A:.L|
|00004820| 6f 6f 6b 20 66 6f 72 20 | 61 20 70 72 6f 67 72 61 |ook for |a progra|
|00004830| 6d 20 63 61 6c 6c 65 64 | 20 75 6e 69 66 64 65 66 |m called| unifdef|
|00004840| 2c 20 72 6d 69 66 64 65 | 66 2c 20 6f 72 20 73 63 |, rmifde|f, or sc|
|00004850| 70 70 2e 0a 0a 36 2e 39 | 3a 09 48 6f 77 20 63 61 |pp...6.9|:.How ca|
|00004860| 6e 20 49 20 6c 69 73 74 | 20 61 6c 6c 20 6f 66 20 |n I list| all of |
|00004870| 74 68 65 20 70 72 65 23 | 64 65 66 69 6e 65 64 20 |the pre#|defined |
|00004880| 69 64 65 6e 74 69 66 69 | 65 72 73 3f 0a 0a 41 3a |identifi|ers?..A:|
|00004890| 09 49 66 20 74 68 65 20 | 63 6f 6d 70 69 6c 65 72 |.If the |compiler|
|000048a0| 20 64 6f 63 75 6d 65 6e | 74 61 74 69 6f 6e 20 69 | documen|tation i|
|000048b0| 73 20 75 6e 68 65 6c 70 | 66 75 6c 2c 20 74 72 79 |s unhelp|ful, try|
|000048c0| 20 65 78 74 72 61 63 74 | 69 6e 67 0a 09 70 72 69 | extract|ing..pri|
|000048d0| 6e 74 61 62 6c 65 20 73 | 74 72 69 6e 67 73 20 66 |ntable s|trings f|
|000048e0| 72 6f 6d 20 74 68 65 20 | 63 6f 6d 70 69 6c 65 72 |rom the |compiler|
|000048f0| 20 6f 72 20 70 72 65 70 | 72 6f 63 65 73 73 6f 72 | or prep|rocessor|
|00004900| 20 65 78 65 63 75 74 61 | 62 6c 65 2e 0a 0a 36 2e | executa|ble...6.|
|00004910| 31 30 3a 09 48 6f 77 20 | 63 61 6e 20 49 20 77 72 |10:.How |can I wr|
|00004920| 69 74 65 20 61 20 63 70 | 70 20 6d 61 63 72 6f 20 |ite a cp|p macro |
|00004930| 77 68 69 63 68 20 74 61 | 6b 65 73 20 61 20 76 61 |which ta|kes a va|
|00004940| 72 69 61 62 6c 65 20 6e | 75 6d 62 65 72 20 6f 66 |riable n|umber of|
|00004950| 0a 09 61 72 67 75 6d 65 | 6e 74 73 3f 0a 0a 41 3a |..argume|nts?..A:|
|00004960| 09 48 65 72 65 20 69 73 | 20 6f 6e 65 20 70 6f 70 |.Here is| one pop|
|00004970| 75 6c 61 72 20 74 72 69 | 63 6b 2e 20 20 4e 6f 74 |ular tri|ck. Not|
|00004980| 65 20 74 68 61 74 20 74 | 68 65 20 70 61 72 65 6e |e that t|he paren|
|00004990| 74 68 65 73 65 73 20 61 | 72 6f 75 6e 64 0a 09 70 |theses a|round..p|
|000049a0| 72 69 6e 74 66 27 73 20 | 61 72 67 75 6d 65 6e 74 |rintf's |argument|
|000049b0| 20 6c 69 73 74 20 61 72 | 65 20 69 6e 20 74 68 65 | list ar|e in the|
|000049c0| 20 6d 61 63 72 6f 20 63 | 61 6c 6c 2c 20 6e 6f 74 | macro c|all, not|
|000049d0| 20 74 68 65 0a 09 64 65 | 66 69 6e 69 74 69 6f 6e | the..de|finition|
|000049e0| 2e 0a 0a 09 09 23 64 65 | 66 69 6e 65 20 44 45 42 |.....#de|fine DEB|
|000049f0| 55 47 28 61 72 67 73 29 | 20 28 70 72 69 6e 74 66 |UG(args)| (printf|
|00004a00| 28 22 44 45 42 55 47 3a | 20 22 29 2c 20 70 72 69 |("DEBUG:| "), pri|
|00004a10| 6e 74 66 20 61 72 67 73 | 29 0a 0a 09 09 69 66 28 |ntf args|)....if(|
|00004a20| 6e 20 21 3d 20 30 29 20 | 44 45 42 55 47 28 28 22 |n != 0) |DEBUG(("|
|00004a30| 6e 20 69 73 20 25 64 5c | 6e 22 2c 20 6e 29 29 3b |n is %d\|n", n));|
|00004a40| 0a 0a 0a 53 65 63 74 69 | 6f 6e 20 37 2e 20 56 61 |...Secti|on 7. Va|
|00004a50| 72 69 61 62 6c 65 2d 4c | 65 6e 67 74 68 20 41 72 |riable-L|ength Ar|
|00004a60| 67 75 6d 65 6e 74 20 4c | 69 73 74 73 0a 0a 37 2e |gument L|ists..7.|
|00004a70| 31 3a 09 48 6f 77 20 63 | 61 6e 20 49 20 77 72 69 |1:.How c|an I wri|
|00004a80| 74 65 20 61 20 66 75 6e | 63 74 69 6f 6e 20 74 68 |te a fun|ction th|
|00004a90| 61 74 20 74 61 6b 65 73 | 20 61 20 76 61 72 69 61 |at takes| a varia|
|00004aa0| 62 6c 65 20 6e 75 6d 62 | 65 72 20 6f 66 0a 09 61 |ble numb|er of..a|
|00004ab0| 72 67 75 6d 65 6e 74 73 | 3f 0a 0a 41 3a 09 55 73 |rguments|?..A:.Us|
|00004ac0| 65 20 74 68 65 20 3c 73 | 74 64 61 72 67 2e 68 3e |e the <s|tdarg.h>|
|00004ad0| 20 28 6f 72 20 6f 6c 64 | 65 72 20 3c 76 61 72 61 | (or old|er <vara|
|00004ae0| 72 67 73 2e 68 3e 29 20 | 68 65 61 64 65 72 2e 0a |rgs.h>) |header..|
|00004af0| 0a 37 2e 32 3a 09 48 6f | 77 20 63 61 6e 20 49 20 |.7.2:.Ho|w can I |
|00004b00| 77 72 69 74 65 20 61 20 | 66 75 6e 63 74 69 6f 6e |write a |function|
|00004b10| 20 74 68 61 74 20 74 61 | 6b 65 73 20 61 20 66 6f | that ta|kes a fo|
|00004b20| 72 6d 61 74 20 73 74 72 | 69 6e 67 20 61 6e 64 20 |rmat str|ing and |
|00004b30| 61 0a 09 76 61 72 69 61 | 62 6c 65 20 6e 75 6d 62 |a..varia|ble numb|
|00004b40| 65 72 20 6f 66 20 61 72 | 67 75 6d 65 6e 74 73 2c |er of ar|guments,|
|00004b50| 20 6c 69 6b 65 20 70 72 | 69 6e 74 66 2c 20 61 6e | like pr|intf, an|
|00004b60| 64 20 70 61 73 73 65 73 | 20 74 68 65 6d 20 74 6f |d passes| them to|
|00004b70| 0a 09 70 72 69 6e 74 66 | 20 74 6f 20 64 6f 20 6d |..printf| to do m|
|00004b80| 6f 73 74 20 6f 66 20 74 | 68 65 20 77 6f 72 6b 3f |ost of t|he work?|
|00004b90| 0a 0a 41 3a 09 55 73 65 | 20 76 70 72 69 6e 74 66 |..A:.Use| vprintf|
|00004ba0| 2c 20 76 66 70 72 69 6e | 74 66 2c 20 6f 72 20 76 |, vfprin|tf, or v|
|00004bb0| 73 70 72 69 6e 74 66 2e | 0a 0a 37 2e 33 3a 09 48 |sprintf.|..7.3:.H|
|00004bc0| 6f 77 20 63 61 6e 20 49 | 20 64 69 73 63 6f 76 65 |ow can I| discove|
|00004bd0| 72 20 68 6f 77 20 6d 61 | 6e 79 20 61 72 67 75 6d |r how ma|ny argum|
|00004be0| 65 6e 74 73 20 61 20 66 | 75 6e 63 74 69 6f 6e 20 |ents a f|unction |
|00004bf0| 77 61 73 20 61 63 74 75 | 61 6c 6c 79 0a 09 63 61 |was actu|ally..ca|
|00004c00| 6c 6c 65 64 20 77 69 74 | 68 3f 0a 0a 41 3a 09 41 |lled wit|h?..A:.A|
|00004c10| 6e 79 20 66 75 6e 63 74 | 69 6f 6e 20 77 68 69 63 |ny funct|ion whic|
|00004c20| 68 20 74 61 6b 65 73 20 | 61 20 76 61 72 69 61 62 |h takes |a variab|
|00004c30| 6c 65 20 6e 75 6d 62 65 | 72 20 6f 66 20 61 72 67 |le numbe|r of arg|
|00004c40| 75 6d 65 6e 74 73 20 6d | 75 73 74 20 62 65 0a 09 |uments m|ust be..|
|00004c50| 61 62 6c 65 20 74 6f 20 | 64 65 74 65 72 6d 69 6e |able to |determin|
|00004c60| 65 20 66 72 6f 6d 20 74 | 68 65 20 61 72 67 75 6d |e from t|he argum|
|00004c70| 65 6e 74 73 20 74 68 65 | 6d 73 65 6c 76 65 73 20 |ents the|mselves |
|00004c80| 68 6f 77 20 6d 61 6e 79 | 20 6f 66 20 74 68 65 6d |how many| of them|
|00004c90| 0a 09 74 68 65 72 65 20 | 61 72 65 2e 0a 0a 37 2e |..there |are...7.|
|00004ca0| 34 3a 09 49 20 63 61 6e | 27 74 20 67 65 74 20 74 |4:.I can|'t get t|
|00004cb0| 68 65 20 76 61 5f 61 72 | 67 20 6d 61 63 72 6f 20 |he va_ar|g macro |
|00004cc0| 74 6f 20 70 75 6c 6c 20 | 69 6e 20 61 6e 20 61 72 |to pull |in an ar|
|00004cd0| 67 75 6d 65 6e 74 20 6f | 66 20 74 79 70 65 0a 09 |gument o|f type..|
|00004ce0| 70 6f 69 6e 74 65 72 2d | 74 6f 2d 66 75 6e 63 74 |pointer-|to-funct|
|00004cf0| 69 6f 6e 2e 0a 0a 41 3a | 09 55 73 65 20 61 20 74 |ion...A:|.Use a t|
|00004d00| 79 70 65 64 65 66 2e 0a | 0a 37 2e 35 3a 09 48 6f |ypedef..|.7.5:.Ho|
|00004d10| 77 20 63 61 6e 20 49 20 | 77 72 69 74 65 20 61 20 |w can I |write a |
|00004d20| 66 75 6e 63 74 69 6f 6e | 20 77 68 69 63 68 20 74 |function| which t|
|00004d30| 61 6b 65 73 20 61 20 76 | 61 72 69 61 62 6c 65 20 |akes a v|ariable |
|00004d40| 6e 75 6d 62 65 72 20 6f | 66 0a 09 61 72 67 75 6d |number o|f..argum|
|00004d50| 65 6e 74 73 20 61 6e 64 | 20 70 61 73 73 65 73 20 |ents and| passes |
|00004d60| 74 68 65 6d 20 74 6f 20 | 73 6f 6d 65 20 6f 74 68 |them to |some oth|
|00004d70| 65 72 20 66 75 6e 63 74 | 69 6f 6e 20 28 77 68 69 |er funct|ion (whi|
|00004d80| 63 68 20 74 61 6b 65 73 | 20 61 0a 09 76 61 72 69 |ch takes| a..vari|
|00004d90| 61 62 6c 65 20 6e 75 6d | 62 65 72 20 6f 66 20 61 |able num|ber of a|
|00004da0| 72 67 75 6d 65 6e 74 73 | 29 3f 0a 0a 41 3a 09 49 |rguments|)?..A:.I|
|00004db0| 6e 20 67 65 6e 65 72 61 | 6c 2c 20 79 6f 75 20 63 |n genera|l, you c|
|00004dc0| 61 6e 6e 6f 74 2e 0a 0a | 37 2e 36 3a 09 48 6f 77 |annot...|7.6:.How|
|00004dd0| 20 63 61 6e 20 49 20 63 | 61 6c 6c 20 61 20 66 75 | can I c|all a fu|
|00004de0| 6e 63 74 69 6f 6e 20 77 | 69 74 68 20 61 6e 20 61 |nction w|ith an a|
|00004df0| 72 67 75 6d 65 6e 74 20 | 6c 69 73 74 20 62 75 69 |rgument |list bui|
|00004e00| 6c 74 20 75 70 20 61 74 | 20 72 75 6e 0a 09 74 69 |lt up at| run..ti|
|00004e10| 6d 65 3f 0a 0a 41 3a 09 | 59 6f 75 20 63 61 6e 27 |me?..A:.|You can'|
|00004e20| 74 2e 0a 0a 0a 53 65 63 | 74 69 6f 6e 20 38 2e 20 |t....Sec|tion 8. |
|00004e30| 42 6f 6f 6c 65 61 6e 20 | 45 78 70 72 65 73 73 69 |Boolean |Expressi|
|00004e40| 6f 6e 73 20 61 6e 64 20 | 56 61 72 69 61 62 6c 65 |ons and |Variable|
|00004e50| 73 0a 0a 38 2e 31 3a 09 | 57 68 61 74 20 69 73 20 |s..8.1:.|What is |
|00004e60| 74 68 65 20 72 69 67 68 | 74 20 74 79 70 65 20 74 |the righ|t type t|
|00004e70| 6f 20 75 73 65 20 66 6f | 72 20 62 6f 6f 6c 65 61 |o use fo|r boolea|
|00004e80| 6e 20 76 61 6c 75 65 73 | 20 69 6e 20 43 3f 20 20 |n values| in C? |
|00004e90| 57 68 79 0a 09 69 73 6e | 27 74 20 69 74 20 61 20 |Why..isn|'t it a |
|00004ea0| 73 74 61 6e 64 61 72 64 | 20 74 79 70 65 3f 20 20 |standard| type? |
|00004eb0| 53 68 6f 75 6c 64 20 23 | 64 65 66 69 6e 65 73 20 |Should #|defines |
|00004ec0| 6f 72 20 65 6e 75 6d 73 | 20 62 65 20 75 73 65 64 |or enums| be used|
|00004ed0| 20 66 6f 72 0a 09 74 68 | 65 20 74 72 75 65 20 61 | for..th|e true a|
|00004ee0| 6e 64 20 66 61 6c 73 65 | 20 76 61 6c 75 65 73 3f |nd false| values?|
|00004ef0| 0a 0a 41 3a 09 43 20 64 | 6f 65 73 20 6e 6f 74 20 |..A:.C d|oes not |
|00004f00| 70 72 6f 76 69 64 65 20 | 61 20 73 74 61 6e 64 61 |provide |a standa|
|00004f10| 72 64 20 62 6f 6f 6c 65 | 61 6e 20 74 79 70 65 2c |rd boole|an type,|
|00004f20| 20 62 65 63 61 75 73 65 | 20 70 69 63 6b 69 6e 67 | because| picking|
|00004f30| 20 6f 6e 65 0a 09 69 6e | 76 6f 6c 76 65 73 20 61 | one..in|volves a|
|00004f40| 20 73 70 61 63 65 2f 74 | 69 6d 65 20 74 72 61 64 | space/t|ime trad|
|00004f50| 65 6f 66 66 20 77 68 69 | 63 68 20 69 73 20 62 65 |eoff whi|ch is be|
|00004f60| 73 74 20 64 65 63 69 64 | 65 64 20 62 79 20 74 68 |st decid|ed by th|
|00004f70| 65 0a 09 70 72 6f 67 72 | 61 6d 6d 65 72 2e 20 20 |e..progr|ammer. |
|00004f80| 54 68 65 20 63 68 6f 69 | 63 65 20 62 65 74 77 65 |The choi|ce betwe|
|00004f90| 65 6e 20 23 64 65 66 69 | 6e 65 73 20 61 6e 64 20 |en #defi|nes and |
|00004fa0| 65 6e 75 6d 73 20 69 73 | 20 61 72 62 69 74 72 61 |enums is| arbitra|
|00004fb0| 72 79 0a 09 61 6e 64 20 | 6e 6f 74 20 74 65 72 72 |ry..and |not terr|
|00004fc0| 69 62 6c 79 20 69 6e 74 | 65 72 65 73 74 69 6e 67 |ibly int|eresting|
|00004fd0| 2e 0a 0a 38 2e 32 3a 09 | 57 68 61 74 20 69 66 20 |...8.2:.|What if |
|00004fe0| 61 20 62 75 69 6c 74 2d | 69 6e 20 62 6f 6f 6c 65 |a built-|in boole|
|00004ff0| 61 6e 20 6f 72 20 72 65 | 6c 61 74 69 6f 6e 61 6c |an or re|lational|
|00005000| 20 6f 70 65 72 61 74 6f | 72 20 22 72 65 74 75 72 | operato|r "retur|
|00005010| 6e 73 22 0a 09 73 6f 6d | 65 74 68 69 6e 67 20 6f |ns"..som|ething o|
|00005020| 74 68 65 72 20 74 68 61 | 6e 20 31 3f 0a 0a 41 3a |ther tha|n 1?..A:|
|00005030| 09 57 68 65 6e 20 61 20 | 62 6f 6f 6c 65 61 6e 20 |.When a |boolean |
|00005040| 76 61 6c 75 65 20 69 73 | 20 67 65 6e 65 72 61 74 |value is| generat|
|00005050| 65 64 20 62 79 20 61 20 | 62 75 69 6c 74 2d 69 6e |ed by a |built-in|
|00005060| 20 6f 70 65 72 61 74 6f | 72 2c 20 69 74 20 69 73 | operato|r, it is|
|00005070| 0a 09 67 75 61 72 61 6e | 74 65 65 64 20 74 6f 20 |..guaran|teed to |
|00005080| 62 65 20 31 20 6f 72 20 | 30 2e 20 20 28 54 68 69 |be 1 or |0. (Thi|
|00005090| 73 20 69 73 20 5f 6e 6f | 74 5f 20 74 72 75 65 20 |s is _no|t_ true |
|000050a0| 66 6f 72 20 73 6f 6d 65 | 20 6c 69 62 72 61 72 79 |for some| library|
|000050b0| 0a 09 72 6f 75 74 69 6e | 65 73 20 73 75 63 68 20 |..routin|es such |
|000050c0| 61 73 20 69 73 61 6c 70 | 68 61 2e 29 0a 0a 0a 53 |as isalp|ha.)...S|
|000050d0| 65 63 74 69 6f 6e 20 39 | 2e 20 53 74 72 75 63 74 |ection 9|. Struct|
|000050e0| 73 2c 20 45 6e 75 6d 73 | 2c 20 61 6e 64 20 55 6e |s, Enums|, and Un|
|000050f0| 69 6f 6e 73 0a 0a 39 2e | 31 3a 09 57 68 61 74 20 |ions..9.|1:.What |
|00005100| 69 73 20 74 68 65 20 64 | 69 66 66 65 72 65 6e 63 |is the d|ifferenc|
|00005110| 65 20 62 65 74 77 65 65 | 6e 20 61 6e 20 65 6e 75 |e betwee|n an enu|
|00005120| 6d 20 61 6e 64 20 61 20 | 73 65 72 69 65 73 20 6f |m and a |series o|
|00005130| 66 0a 09 70 72 65 70 72 | 6f 63 65 73 73 6f 72 20 |f..prepr|ocessor |
|00005140| 23 64 65 66 69 6e 65 73 | 3f 0a 0a 41 3a 09 41 74 |#defines|?..A:.At|
|00005150| 20 74 68 65 20 70 72 65 | 73 65 6e 74 20 74 69 6d | the pre|sent tim|
|00005160| 65 2c 20 74 68 65 72 65 | 20 69 73 20 6c 69 74 74 |e, there| is litt|
|00005170| 6c 65 20 64 69 66 66 65 | 72 65 6e 63 65 2e 20 20 |le diffe|rence. |
|00005180| 54 68 65 20 41 4e 53 49 | 0a 09 73 74 61 6e 64 61 |The ANSI|..standa|
|00005190| 72 64 20 73 74 61 74 65 | 73 20 74 68 61 74 20 65 |rd state|s that e|
|000051a0| 6e 75 6d 65 72 61 74 69 | 6f 6e 73 20 61 72 65 20 |numerati|ons are |
|000051b0| 63 6f 6d 70 61 74 69 62 | 6c 65 20 77 69 74 68 20 |compatib|le with |
|000051c0| 69 6e 74 65 67 72 61 6c | 0a 09 74 79 70 65 73 2e |integral|..types.|
|000051d0| 0a 0a 39 2e 32 3a 09 49 | 20 68 65 61 72 64 20 74 |..9.2:.I| heard t|
|000051e0| 68 61 74 20 73 74 72 75 | 63 74 75 72 65 73 20 63 |hat stru|ctures c|
|000051f0| 6f 75 6c 64 20 62 65 20 | 61 73 73 69 67 6e 65 64 |ould be |assigned|
|00005200| 20 74 6f 20 76 61 72 69 | 61 62 6c 65 73 20 61 6e | to vari|ables an|
|00005210| 64 0a 09 70 61 73 73 65 | 64 20 74 6f 20 61 6e 64 |d..passe|d to and|
|00005220| 20 66 72 6f 6d 20 66 75 | 6e 63 74 69 6f 6e 73 2c | from fu|nctions,|
|00005230| 20 62 75 74 20 4b 26 52 | 20 49 20 73 61 79 73 20 | but K&R| I says |
|00005240| 6e 6f 74 2e 0a 0a 41 3a | 09 54 68 65 73 65 20 6f |not...A:|.These o|
|00005250| 70 65 72 61 74 69 6f 6e | 73 20 61 72 65 20 73 75 |peration|s are su|
|00005260| 70 70 6f 72 74 65 64 20 | 62 79 20 61 6c 6c 20 6d |pported |by all m|
|00005270| 6f 64 65 72 6e 20 63 6f | 6d 70 69 6c 65 72 73 2e |odern co|mpilers.|
|00005280| 0a 0a 39 2e 33 3a 09 48 | 6f 77 20 64 6f 65 73 20 |..9.3:.H|ow does |
|00005290| 73 74 72 75 63 74 20 70 | 61 73 73 69 6e 67 20 61 |struct p|assing a|
|000052a0| 6e 64 20 72 65 74 75 72 | 6e 69 6e 67 20 77 6f 72 |nd retur|ning wor|
|000052b0| 6b 3f 0a 0a 41 3a 09 49 | 66 20 79 6f 75 20 72 65 |k?..A:.I|f you re|
|000052c0| 61 6c 6c 79 20 6e 65 65 | 64 20 74 6f 20 6b 6e 6f |ally nee|d to kno|
|000052d0| 77 2c 20 73 65 65 20 74 | 68 65 20 75 6e 61 62 72 |w, see t|he unabr|
|000052e0| 69 64 67 65 64 20 6c 69 | 73 74 2e 0a 0a 39 2e 34 |idged li|st...9.4|
|000052f0| 3a 09 49 20 68 61 76 65 | 20 61 20 70 72 6f 67 72 |:.I have| a progr|
|00005300| 61 6d 20 77 68 69 63 68 | 20 77 6f 72 6b 73 20 63 |am which| works c|
|00005310| 6f 72 72 65 63 74 6c 79 | 2c 20 62 75 74 20 64 75 |orrectly|, but du|
|00005320| 6d 70 73 20 63 6f 72 65 | 20 61 66 74 65 72 20 69 |mps core| after i|
|00005330| 74 0a 09 66 69 6e 69 73 | 68 65 73 2e 20 20 57 68 |t..finis|hes. Wh|
|00005340| 79 3f 0a 0a 41 3a 09 43 | 68 65 63 6b 20 74 6f 20 |y?..A:.C|heck to |
|00005350| 73 65 65 20 69 66 20 61 | 20 73 74 72 75 63 74 75 |see if a| structu|
|00005360| 72 65 20 74 79 70 65 20 | 64 65 63 6c 61 72 61 74 |re type |declarat|
|00005370| 69 6f 6e 20 6a 75 73 74 | 20 62 65 66 6f 72 65 20 |ion just| before |
|00005380| 6d 61 69 6e 20 69 73 0a | 09 6d 69 73 73 69 6e 67 |main is.|.missing|
|00005390| 20 69 74 73 20 74 72 61 | 69 6c 69 6e 67 20 73 65 | its tra|iling se|
|000053a0| 6d 69 63 6f 6c 6f 6e 2c | 20 63 61 75 73 69 6e 67 |micolon,| causing|
|000053b0| 20 74 68 65 20 63 6f 6d | 70 69 6c 65 72 20 74 6f | the com|piler to|
|000053c0| 20 62 65 6c 69 65 76 65 | 0a 09 74 68 61 74 20 6d | believe|..that m|
|000053d0| 61 69 6e 20 72 65 74 75 | 72 6e 73 20 61 20 73 74 |ain retu|rns a st|
|000053e0| 72 75 63 74 75 72 65 2e | 20 20 53 65 65 20 61 6c |ructure.| See al|
|000053f0| 73 6f 20 71 75 65 73 74 | 69 6f 6e 20 31 37 2e 32 |so quest|ion 17.2|
|00005400| 31 2e 0a 0a 39 2e 35 3a | 09 57 68 79 20 63 61 6e |1...9.5:|.Why can|
|00005410| 27 74 20 79 6f 75 20 63 | 6f 6d 70 61 72 65 20 73 |'t you c|ompare s|
|00005420| 74 72 75 63 74 73 3f 0a | 0a 41 3a 09 54 68 65 72 |tructs?.|.A:.Ther|
|00005430| 65 20 69 73 20 6e 6f 20 | 72 65 61 73 6f 6e 61 62 |e is no |reasonab|
|00005440| 6c 65 20 77 61 79 20 66 | 6f 72 20 61 20 63 6f 6d |le way f|or a com|
|00005450| 70 69 6c 65 72 20 74 6f | 20 69 6d 70 6c 65 6d 65 |piler to| impleme|
|00005460| 6e 74 20 73 74 72 75 63 | 74 0a 09 63 6f 6d 70 61 |nt struc|t..compa|
|00005470| 72 69 73 6f 6e 20 77 68 | 69 63 68 20 69 73 20 63 |rison wh|ich is c|
|00005480| 6f 6e 73 69 73 74 65 6e | 74 20 77 69 74 68 20 43 |onsisten|t with C|
|00005490| 27 73 20 6c 6f 77 2d 6c | 65 76 65 6c 20 66 6c 61 |'s low-l|evel fla|
|000054a0| 76 6f 72 2e 0a 0a 39 2e | 36 3a 09 48 6f 77 20 63 |vor...9.|6:.How c|
|000054b0| 61 6e 20 49 20 72 65 61 | 64 2f 77 72 69 74 65 20 |an I rea|d/write |
|000054c0| 73 74 72 75 63 74 73 20 | 66 72 6f 6d 2f 74 6f 20 |structs |from/to |
|000054d0| 64 61 74 61 20 66 69 6c | 65 73 3f 0a 0a 41 3a 09 |data fil|es?..A:.|
|000054e0| 49 74 20 69 73 20 72 65 | 6c 61 74 69 76 65 6c 79 |It is re|latively|
|000054f0| 20 73 74 72 61 69 67 68 | 74 66 6f 72 77 61 72 64 | straigh|tforward|
|00005500| 20 74 6f 20 75 73 65 20 | 66 72 65 61 64 20 61 6e | to use |fread an|
|00005510| 64 20 66 77 72 69 74 65 | 2e 0a 0a 39 2e 37 3a 09 |d fwrite|...9.7:.|
|00005520| 49 20 63 61 6d 65 20 61 | 63 72 6f 73 73 20 73 6f |I came a|cross so|
|00005530| 6d 65 20 63 6f 64 65 20 | 74 68 61 74 20 64 65 63 |me code |that dec|
|00005540| 6c 61 72 65 64 20 61 20 | 73 74 72 75 63 74 75 72 |lared a |structur|
|00005550| 65 20 77 69 74 68 20 74 | 68 65 20 6c 61 73 74 0a |e with t|he last.|
|00005560| 09 6d 65 6d 62 65 72 20 | 61 6e 20 61 72 72 61 79 |.member |an array|
|00005570| 20 6f 66 20 6f 6e 65 20 | 65 6c 65 6d 65 6e 74 2c | of one |element,|
|00005580| 20 61 6e 64 20 74 68 65 | 6e 20 64 69 64 20 73 6f | and the|n did so|
|00005590| 6d 65 20 74 72 69 63 6b | 79 0a 09 61 6c 6c 6f 63 |me trick|y..alloc|
|000055a0| 61 74 69 6f 6e 20 74 6f | 20 6d 61 6b 65 20 74 68 |ation to| make th|
|000055b0| 65 20 61 72 72 61 79 20 | 61 63 74 20 6c 69 6b 65 |e array |act like|
|000055c0| 20 69 74 20 68 61 64 20 | 73 65 76 65 72 61 6c 20 | it had |several |
|000055d0| 65 6c 65 6d 65 6e 74 73 | 2e 0a 09 49 73 20 74 68 |elements|...Is th|
|000055e0| 69 73 20 6c 65 67 61 6c | 20 61 6e 64 2f 6f 72 20 |is legal| and/or |
|000055f0| 70 6f 72 74 61 62 6c 65 | 3f 0a 0a 41 3a 09 41 6e |portable|?..A:.An|
|00005600| 20 41 4e 53 49 20 49 6e | 74 65 72 70 72 65 74 61 | ANSI In|terpreta|
|00005610| 74 69 6f 6e 20 52 75 6c | 69 6e 67 20 68 61 73 20 |tion Rul|ing has |
|00005620| 64 65 65 6d 65 64 20 69 | 74 20 74 6f 20 62 65 20 |deemed i|t to be |
|00005630| 6e 6f 74 20 73 74 72 69 | 63 74 6c 79 0a 09 63 6f |not stri|ctly..co|
|00005640| 6e 66 6f 72 6d 69 6e 67 | 2e 0a 0a 39 2e 38 3a 09 |nforming|...9.8:.|
|00005650| 48 6f 77 20 63 61 6e 20 | 49 20 64 65 74 65 72 6d |How can |I determ|
|00005660| 69 6e 65 20 74 68 65 20 | 62 79 74 65 20 6f 66 66 |ine the |byte off|
|00005670| 73 65 74 20 6f 66 20 61 | 20 66 69 65 6c 64 20 77 |set of a| field w|
|00005680| 69 74 68 69 6e 20 61 0a | 09 73 74 72 75 63 74 75 |ithin a.|.structu|
|00005690| 72 65 3f 0a 0a 41 3a 09 | 41 4e 53 49 20 43 20 64 |re?..A:.|ANSI C d|
|000056a0| 65 66 69 6e 65 73 20 74 | 68 65 20 6f 66 66 73 65 |efines t|he offse|
|000056b0| 74 6f 66 20 6d 61 63 72 | 6f 2c 20 77 68 69 63 68 |tof macr|o, which|
|000056c0| 20 73 68 6f 75 6c 64 20 | 62 65 20 75 73 65 64 20 | should |be used |
|000056d0| 69 66 0a 09 61 76 61 69 | 6c 61 62 6c 65 2e 0a 0a |if..avai|lable...|
|000056e0| 39 2e 39 3a 09 48 6f 77 | 20 63 61 6e 20 49 20 61 |9.9:.How| can I a|
|000056f0| 63 63 65 73 73 20 73 74 | 72 75 63 74 75 72 65 20 |ccess st|ructure |
|00005700| 66 69 65 6c 64 73 20 62 | 79 20 6e 61 6d 65 20 61 |fields b|y name a|
|00005710| 74 20 72 75 6e 20 74 69 | 6d 65 3f 0a 0a 41 3a 09 |t run ti|me?..A:.|
|00005720| 42 75 69 6c 64 20 61 20 | 74 61 62 6c 65 20 6f 66 |Build a |table of|
|00005730| 20 6e 61 6d 65 73 20 61 | 6e 64 20 6f 66 66 73 65 | names a|nd offse|
|00005740| 74 73 2c 20 75 73 69 6e | 67 20 74 68 65 20 6f 66 |ts, usin|g the of|
|00005750| 66 73 65 74 6f 66 28 29 | 20 6d 61 63 72 6f 2e 0a |fsetof()| macro..|
|00005760| 0a 39 2e 31 30 3a 09 57 | 68 79 20 64 6f 65 73 20 |.9.10:.W|hy does |
|00005770| 73 69 7a 65 6f 66 20 72 | 65 70 6f 72 74 20 61 20 |sizeof r|eport a |
|00005780| 6c 61 72 67 65 72 20 73 | 69 7a 65 20 74 68 61 6e |larger s|ize than|
|00005790| 20 49 20 65 78 70 65 63 | 74 20 66 6f 72 20 61 0a | I expec|t for a.|
|000057a0| 09 73 74 72 75 63 74 75 | 72 65 20 74 79 70 65 2c |.structu|re type,|
|000057b0| 20 61 73 20 69 66 20 74 | 68 65 72 65 20 77 61 73 | as if t|here was|
|000057c0| 20 70 61 64 64 69 6e 67 | 20 61 74 20 74 68 65 20 | padding| at the |
|000057d0| 65 6e 64 3f 0a 0a 41 3a | 09 54 68 65 20 61 6c 69 |end?..A:|.The ali|
|000057e0| 67 6e 6d 65 6e 74 20 6f | 66 20 61 72 72 61 79 73 |gnment o|f arrays|
|000057f0| 20 6f 66 20 73 74 72 75 | 63 74 75 72 65 73 20 6d | of stru|ctures m|
|00005800| 75 73 74 20 62 65 20 70 | 72 65 73 65 72 76 65 64 |ust be p|reserved|
|00005810| 2e 0a 0a 39 2e 31 31 3a | 09 48 6f 77 20 63 61 6e |...9.11:|.How can|
|00005820| 20 49 20 74 75 72 6e 20 | 6f 66 66 20 73 74 72 75 | I turn |off stru|
|00005830| 63 74 75 72 65 20 70 61 | 64 64 69 6e 67 3f 0a 0a |cture pa|dding?..|
|00005840| 41 3a 09 54 68 65 72 65 | 20 69 73 20 6e 6f 20 73 |A:.There| is no s|
|00005850| 74 61 6e 64 61 72 64 20 | 6d 65 74 68 6f 64 2e 0a |tandard |method..|
|00005860| 0a 39 2e 31 32 3a 09 43 | 61 6e 20 49 20 69 6e 69 |.9.12:.C|an I ini|
|00005870| 74 69 61 6c 69 7a 65 20 | 75 6e 69 6f 6e 73 3f 0a |tialize |unions?.|
|00005880| 0a 41 3a 09 41 4e 53 49 | 20 53 74 61 6e 64 61 72 |.A:.ANSI| Standar|
|00005890| 64 20 43 20 61 6c 6c 6f | 77 73 20 61 6e 20 69 6e |d C allo|ws an in|
|000058a0| 69 74 69 61 6c 69 7a 65 | 72 20 66 6f 72 20 74 68 |itialize|r for th|
|000058b0| 65 20 66 69 72 73 74 20 | 6d 65 6d 62 65 72 2e 0a |e first |member..|
|000058c0| 0a 39 2e 31 33 3a 09 43 | 61 6e 20 49 20 70 61 73 |.9.13:.C|an I pas|
|000058d0| 73 20 63 6f 6e 73 74 61 | 6e 74 20 76 61 6c 75 65 |s consta|nt value|
|000058e0| 73 20 74 6f 20 72 6f 75 | 74 69 6e 65 73 20 77 68 |s to rou|tines wh|
|000058f0| 69 63 68 20 61 63 63 65 | 70 74 20 73 74 72 75 63 |ich acce|pt struc|
|00005900| 74 0a 09 61 72 67 75 6d | 65 6e 74 73 3f 0a 0a 41 |t..argum|ents?..A|
|00005910| 3a 09 4e 6f 2e 20 20 43 | 20 68 61 73 20 6e 6f 20 |:.No. C| has no |
|00005920| 77 61 79 20 6f 66 20 67 | 65 6e 65 72 61 74 69 6e |way of g|eneratin|
|00005930| 67 20 61 6e 6f 6e 79 6d | 6f 75 73 20 73 74 72 75 |g anonym|ous stru|
|00005940| 63 74 20 76 61 6c 75 65 | 73 2e 0a 0a 0a 53 65 63 |ct value|s....Sec|
|00005950| 74 69 6f 6e 20 31 30 2e | 20 44 65 63 6c 61 72 61 |tion 10.| Declara|
|00005960| 74 69 6f 6e 73 0a 0a 31 | 30 2e 31 3a 09 48 6f 77 |tions..1|0.1:.How|
|00005970| 20 64 6f 20 79 6f 75 20 | 64 65 63 69 64 65 20 77 | do you |decide w|
|00005980| 68 69 63 68 20 69 6e 74 | 65 67 65 72 20 74 79 70 |hich int|eger typ|
|00005990| 65 20 74 6f 20 75 73 65 | 3f 0a 0a 41 3a 09 49 66 |e to use|?..A:.If|
|000059a0| 20 79 6f 75 20 6d 69 67 | 68 74 20 6e 65 65 64 20 | you mig|ht need |
|000059b0| 6c 61 72 67 65 20 76 61 | 6c 75 65 73 2c 20 75 73 |large va|lues, us|
|000059c0| 65 20 6c 6f 6e 67 2e 20 | 20 4f 74 68 65 72 77 69 |e long. | Otherwi|
|000059d0| 73 65 2c 20 69 66 20 73 | 70 61 63 65 0a 09 69 73 |se, if s|pace..is|
|000059e0| 20 76 65 72 79 20 69 6d | 70 6f 72 74 61 6e 74 2c | very im|portant,|
|000059f0| 20 75 73 65 20 73 68 6f | 72 74 2e 20 20 4f 74 68 | use sho|rt. Oth|
|00005a00| 65 72 77 69 73 65 2c 20 | 75 73 65 20 69 6e 74 2e |erwise, |use int.|
|00005a10| 0a 0a 31 30 2e 32 3a 09 | 57 68 61 74 20 73 68 6f |..10.2:.|What sho|
|00005a20| 75 6c 64 20 74 68 65 20 | 36 34 2d 62 69 74 20 74 |uld the |64-bit t|
|00005a30| 79 70 65 20 6f 6e 20 6e | 65 77 2c 20 36 34 2d 62 |ype on n|ew, 64-b|
|00005a40| 69 74 20 6d 61 63 68 69 | 6e 65 73 20 62 65 3f 0a |it machi|nes be?.|
|00005a50| 0a 41 3a 09 54 68 65 72 | 65 20 61 72 65 20 61 72 |.A:.Ther|e are ar|
|00005a60| 67 75 6d 65 6e 74 73 20 | 69 6e 20 66 61 76 6f 72 |guments |in favor|
|00005a70| 20 6f 66 20 6c 6f 6e 67 | 20 69 6e 74 20 61 6e 64 | of long| int and|
|00005a80| 20 6c 6f 6e 67 20 6c 6f | 6e 67 20 69 6e 74 2c 0a | long lo|ng int,.|
|00005a90| 09 61 6d 6f 6e 67 20 6f | 74 68 65 72 20 6f 70 74 |.among o|ther opt|
|00005aa0| 69 6f 6e 73 2e 0a 0a 31 | 30 2e 33 3a 09 49 20 63 |ions...1|0.3:.I c|
|00005ab0| 61 6e 27 74 20 73 65 65 | 6d 20 74 6f 20 64 65 66 |an't see|m to def|
|00005ac0| 69 6e 65 20 61 20 6c 69 | 6e 6b 65 64 20 6c 69 73 |ine a li|nked lis|
|00005ad0| 74 20 6e 6f 64 65 20 77 | 68 69 63 68 20 63 6f 6e |t node w|hich con|
|00005ae0| 74 61 69 6e 73 20 61 0a | 09 70 6f 69 6e 74 65 72 |tains a.|.pointer|
|00005af0| 20 74 6f 20 69 74 73 65 | 6c 66 2e 0a 0a 41 3a 09 | to itse|lf...A:.|
|00005b00| 53 74 72 75 63 74 73 20 | 69 6e 20 43 20 63 61 6e |Structs |in C can|
|00005b10| 20 63 65 72 74 61 69 6e | 6c 79 20 63 6f 6e 74 61 | certain|ly conta|
|00005b20| 69 6e 20 70 6f 69 6e 74 | 65 72 73 20 74 6f 20 74 |in point|ers to t|
|00005b30| 68 65 6d 73 65 6c 76 65 | 73 3b 20 74 68 65 0a 09 |hemselve|s; the..|
|00005b40| 64 69 73 63 75 73 73 69 | 6f 6e 20 61 6e 64 20 65 |discussi|on and e|
|00005b50| 78 61 6d 70 6c 65 20 69 | 6e 20 73 65 63 74 69 6f |xample i|n sectio|
|00005b60| 6e 20 36 2e 35 20 6f 66 | 20 4b 26 52 20 6d 61 6b |n 6.5 of| K&R mak|
|00005b70| 65 20 74 68 69 73 20 63 | 6c 65 61 72 2e 0a 09 50 |e this c|lear...P|
|00005b80| 72 6f 62 6c 65 6d 73 20 | 61 72 69 73 65 20 69 66 |roblems |arise if|
|00005b90| 20 61 6e 20 61 74 74 65 | 6d 70 74 20 69 73 20 6d | an atte|mpt is m|
|00005ba0| 61 64 65 20 74 6f 20 64 | 65 66 69 6e 65 20 28 61 |ade to d|efine (a|
|00005bb0| 6e 64 20 75 73 65 29 20 | 61 0a 09 74 79 70 65 64 |nd use) |a..typed|
|00005bc0| 65 66 20 69 6e 20 74 68 | 65 20 6d 69 64 73 74 20 |ef in th|e midst |
|00005bd0| 6f 66 20 73 75 63 68 20 | 61 20 64 65 63 6c 61 72 |of such |a declar|
|00005be0| 61 74 69 6f 6e 3b 20 61 | 76 6f 69 64 20 74 68 69 |ation; a|void thi|
|00005bf0| 73 2e 0a 0a 31 30 2e 34 | 3a 09 48 6f 77 20 64 6f |s...10.4|:.How do|
|00005c00| 20 49 20 64 65 63 6c 61 | 72 65 20 61 6e 20 61 72 | I decla|re an ar|
|00005c10| 72 61 79 20 6f 66 20 4e | 20 70 6f 69 6e 74 65 72 |ray of N| pointer|
|00005c20| 73 20 74 6f 20 66 75 6e | 63 74 69 6f 6e 73 20 72 |s to fun|ctions r|
|00005c30| 65 74 75 72 6e 69 6e 67 | 0a 09 70 6f 69 6e 74 65 |eturning|..pointe|
|00005c40| 72 73 20 74 6f 20 66 75 | 6e 63 74 69 6f 6e 73 20 |rs to fu|nctions |
|00005c50| 72 65 74 75 72 6e 69 6e | 67 20 70 6f 69 6e 74 65 |returnin|g pointe|
|00005c60| 72 73 20 74 6f 20 63 68 | 61 72 61 63 74 65 72 73 |rs to ch|aracters|
|00005c70| 3f 0a 0a 41 3a 09 63 68 | 61 72 20 2a 28 2a 28 2a |?..A:.ch|ar *(*(*|
|00005c80| 61 5b 4e 5d 29 28 29 29 | 28 29 3b 0a 09 55 73 69 |a[N])())|();..Usi|
|00005c90| 6e 67 20 61 20 63 68 61 | 69 6e 20 6f 66 20 74 79 |ng a cha|in of ty|
|00005ca0| 70 65 64 65 66 73 2c 20 | 6f 72 20 74 68 65 20 63 |pedefs, |or the c|
|00005cb0| 64 65 63 6c 20 70 72 6f | 67 72 61 6d 2c 20 6d 61 |decl pro|gram, ma|
|00005cc0| 6b 65 73 20 74 68 65 73 | 65 0a 09 64 65 63 6c 61 |kes thes|e..decla|
|00005cd0| 72 61 74 69 6f 6e 73 20 | 65 61 73 69 65 72 2e 0a |rations |easier..|
|00005ce0| 0a 31 30 2e 35 3a 09 48 | 6f 77 20 63 61 6e 20 49 |.10.5:.H|ow can I|
|00005cf0| 20 64 65 63 6c 61 72 65 | 20 61 20 66 75 6e 63 74 | declare| a funct|
|00005d00| 69 6f 6e 20 74 68 61 74 | 20 72 65 74 75 72 6e 73 |ion that| returns|
|00005d10| 20 61 20 70 6f 69 6e 74 | 65 72 20 74 6f 20 61 0a | a point|er to a.|
|00005d20| 09 66 75 6e 63 74 69 6f | 6e 20 6f 66 20 69 74 73 |.functio|n of its|
|00005d30| 20 6f 77 6e 20 74 79 70 | 65 3f 0a 0a 41 3a 09 59 | own typ|e?..A:.Y|
|00005d40| 6f 75 20 63 61 6e 27 74 | 20 64 6f 20 69 74 20 64 |ou can't| do it d|
|00005d50| 69 72 65 63 74 6c 79 2e | 20 20 55 73 65 20 61 20 |irectly.| Use a |
|00005d60| 63 61 73 74 2c 20 6f 72 | 20 77 72 61 70 20 61 20 |cast, or| wrap a |
|00005d70| 73 74 72 75 63 74 20 61 | 72 6f 75 6e 64 0a 09 74 |struct a|round..t|
|00005d80| 68 65 20 70 6f 69 6e 74 | 65 72 20 61 6e 64 20 72 |he point|er and r|
|00005d90| 65 74 75 72 6e 20 74 68 | 61 74 2e 0a 0a 31 30 2e |eturn th|at...10.|
|00005da0| 36 3a 09 4d 79 20 63 6f | 6d 70 69 6c 65 72 20 69 |6:.My co|mpiler i|
|00005db0| 73 20 63 6f 6d 70 6c 61 | 69 6e 69 6e 67 20 61 62 |s compla|ining ab|
|00005dc0| 6f 75 74 20 61 6e 20 69 | 6e 76 61 6c 69 64 20 72 |out an i|nvalid r|
|00005dd0| 65 64 65 63 6c 61 72 61 | 74 69 6f 6e 20 6f 66 20 |edeclara|tion of |
|00005de0| 61 0a 09 66 75 6e 63 74 | 69 6f 6e 2c 20 62 75 74 |a..funct|ion, but|
|00005df0| 20 49 20 6f 6e 6c 79 20 | 64 65 66 69 6e 65 20 69 | I only |define i|
|00005e00| 74 20 6f 6e 63 65 20 61 | 6e 64 20 63 61 6c 6c 20 |t once a|nd call |
|00005e10| 69 74 20 6f 6e 63 65 2e | 0a 0a 41 3a 09 4e 6f 6e |it once.|..A:.Non|
|00005e20| 2d 69 6e 74 20 66 75 6e | 63 74 69 6f 6e 73 20 6d |-int fun|ctions m|
|00005e30| 75 73 74 20 62 65 20 64 | 65 63 6c 61 72 65 64 20 |ust be d|eclared |
|00005e40| 62 65 66 6f 72 65 20 74 | 68 65 79 20 61 72 65 20 |before t|hey are |
|00005e50| 63 61 6c 6c 65 64 2e 0a | 0a 31 30 2e 37 3a 09 57 |called..|.10.7:.W|
|00005e60| 68 61 74 27 73 20 74 68 | 65 20 62 65 73 74 20 77 |hat's th|e best w|
|00005e70| 61 79 20 74 6f 20 64 65 | 63 6c 61 72 65 20 61 6e |ay to de|clare an|
|00005e80| 64 20 64 65 66 69 6e 65 | 20 67 6c 6f 62 61 6c 20 |d define| global |
|00005e90| 76 61 72 69 61 62 6c 65 | 73 3f 0a 0a 41 3a 09 49 |variable|s?..A:.I|
|00005ea0| 74 20 69 73 20 62 65 73 | 74 20 74 6f 20 70 6c 61 |t is bes|t to pla|
|00005eb0| 63 65 20 74 68 65 20 64 | 65 66 69 6e 69 74 69 6f |ce the d|efinitio|
|00005ec0| 6e 20 69 6e 20 73 6f 6d | 65 20 63 65 6e 74 72 61 |n in som|e centra|
|00005ed0| 6c 20 2e 63 20 66 69 6c | 65 2c 20 77 69 74 68 0a |l .c fil|e, with.|
|00005ee0| 09 61 6e 20 65 78 74 65 | 72 6e 61 6c 20 64 65 63 |.an exte|rnal dec|
|00005ef0| 6c 61 72 61 74 69 6f 6e | 20 69 6e 20 61 20 68 65 |laration| in a he|
|00005f00| 61 64 65 72 20 66 69 6c | 65 2e 0a 0a 31 30 2e 38 |ader fil|e...10.8|
|00005f10| 3a 09 57 68 61 74 20 64 | 6f 65 73 20 65 78 74 65 |:.What d|oes exte|
|00005f20| 72 6e 20 6d 65 61 6e 20 | 69 6e 20 61 20 66 75 6e |rn mean |in a fun|
|00005f30| 63 74 69 6f 6e 20 64 65 | 63 6c 61 72 61 74 69 6f |ction de|claratio|
|00005f40| 6e 3f 0a 0a 41 3a 09 4e | 6f 74 68 69 6e 67 2c 20 |n?..A:.N|othing, |
|00005f50| 72 65 61 6c 6c 79 2e 0a | 0a 31 30 2e 39 3a 09 48 |really..|.10.9:.H|
|00005f60| 6f 77 20 64 6f 20 49 20 | 69 6e 69 74 69 61 6c 69 |ow do I |initiali|
|00005f70| 7a 65 20 61 20 70 6f 69 | 6e 74 65 72 20 74 6f 20 |ze a poi|nter to |
|00005f80| 61 20 66 75 6e 63 74 69 | 6f 6e 3f 0a 0a 41 3a 09 |a functi|on?..A:.|
|00005f90| 55 73 65 20 73 6f 6d 65 | 74 68 69 6e 67 20 6c 69 |Use some|thing li|
|00005fa0| 6b 65 20 22 65 78 74 65 | 72 6e 20 69 6e 74 20 66 |ke "exte|rn int f|
|00005fb0| 75 6e 63 28 29 3b 20 69 | 6e 74 20 28 2a 66 70 29 |unc(); i|nt (*fp)|
|00005fc0| 28 29 20 3d 20 66 75 6e | 63 3b 20 22 20 2e 0a 0a |() = fun|c; " ...|
|00005fd0| 31 30 2e 31 30 3a 09 49 | 27 76 65 20 73 65 65 6e |10.10:.I|'ve seen|
|00005fe0| 20 64 69 66 66 65 72 65 | 6e 74 20 6d 65 74 68 6f | differe|nt metho|
|00005ff0| 64 73 20 75 73 65 64 20 | 66 6f 72 20 63 61 6c 6c |ds used |for call|
|00006000| 69 6e 67 20 74 68 72 6f | 75 67 68 20 70 6f 69 6e |ing thro|ugh poin|
|00006010| 74 65 72 73 20 74 6f 0a | 09 66 75 6e 63 74 69 6f |ters to.|.functio|
|00006020| 6e 73 2e 0a 0a 41 3a 09 | 54 68 65 20 65 78 74 72 |ns...A:.|The extr|
|00006030| 61 20 70 61 72 65 6e 74 | 68 65 73 65 73 20 61 6e |a parent|heses an|
|00006040| 64 20 65 78 70 6c 69 63 | 69 74 20 2a 20 61 72 65 |d explic|it * are|
|00006050| 20 6e 6f 77 20 6f 66 66 | 69 63 69 61 6c 6c 79 0a | now off|icially.|
|00006060| 09 6f 70 74 69 6f 6e 61 | 6c 2c 20 61 6c 74 68 6f |.optiona|l, altho|
|00006070| 75 67 68 20 73 6f 6d 65 | 20 6f 6c 64 65 72 20 69 |ugh some| older i|
|00006080| 6d 70 6c 65 6d 65 6e 74 | 61 74 69 6f 6e 73 20 72 |mplement|ations r|
|00006090| 65 71 75 69 72 65 20 74 | 68 65 6d 2e 0a 0a 31 30 |equire t|hem...10|
|000060a0| 2e 31 31 3a 09 57 68 61 | 74 27 73 20 74 68 65 20 |.11:.Wha|t's the |
|000060b0| 61 75 74 6f 20 6b 65 79 | 77 6f 72 64 20 67 6f 6f |auto key|word goo|
|000060c0| 64 20 66 6f 72 3f 0a 0a | 41 3a 09 4e 6f 74 68 69 |d for?..|A:.Nothi|
|000060d0| 6e 67 2e 0a 0a 0a 53 65 | 63 74 69 6f 6e 20 31 31 |ng....Se|ction 11|
|000060e0| 2e 20 53 74 64 69 6f 0a | 0a 31 31 2e 31 3a 09 57 |. Stdio.|.11.1:.W|
|000060f0| 68 61 74 27 73 20 77 72 | 6f 6e 67 20 77 69 74 68 |hat's wr|ong with|
|00006100| 20 74 68 65 20 63 6f 64 | 65 20 22 63 68 61 72 20 | the cod|e "char |
|00006110| 63 3b 20 77 68 69 6c 65 | 28 28 63 20 3d 20 67 65 |c; while|((c = ge|
|00006120| 74 63 68 61 72 28 29 29 | 20 21 3d 20 45 4f 46 29 |tchar())| != EOF)|
|00006130| 2e 2e 2e 22 20 3f 0a 0a | 41 3a 09 54 68 65 20 76 |..." ?..|A:.The v|
|00006140| 61 72 69 61 62 6c 65 20 | 74 6f 20 68 6f 6c 64 20 |ariable |to hold |
|00006150| 67 65 74 63 68 61 72 27 | 73 20 72 65 74 75 72 6e |getchar'|s return|
|00006160| 20 76 61 6c 75 65 20 6d | 75 73 74 20 62 65 20 61 | value m|ust be a|
|00006170| 6e 20 69 6e 74 2e 0a 0a | 31 31 2e 32 3a 09 48 6f |n int...|11.2:.Ho|
|00006180| 77 20 63 61 6e 20 49 20 | 70 72 69 6e 74 20 61 20 |w can I |print a |
|00006190| 27 25 27 20 63 68 61 72 | 61 63 74 65 72 20 77 69 |'%' char|acter wi|
|000061a0| 74 68 20 70 72 69 6e 74 | 66 3f 0a 0a 41 3a 09 25 |th print|f?..A:.%|
|000061b0| 25 20 2e 0a 0a 31 31 2e | 33 3a 09 57 68 79 20 64 |% ...11.|3:.Why d|
|000061c0| 6f 65 73 6e 27 74 20 74 | 68 65 20 63 6f 64 65 20 |oesn't t|he code |
|000061d0| 73 63 61 6e 66 28 22 25 | 64 22 2c 20 69 29 3b 20 |scanf("%|d", i); |
|000061e0| 77 6f 72 6b 3f 0a 0a 41 | 3a 09 73 63 61 6e 66 20 |work?..A|:.scanf |
|000061f0| 6e 65 65 64 73 20 70 6f | 69 6e 74 65 72 73 20 74 |needs po|inters t|
|00006200| 6f 20 74 68 65 20 76 61 | 72 69 61 62 6c 65 73 20 |o the va|riables |
|00006210| 69 74 20 69 73 20 74 6f | 20 66 69 6c 6c 20 69 6e |it is to| fill in|
|00006220| 2e 0a 0a 31 31 2e 34 3a | 09 57 68 79 20 64 6f 65 |...11.4:|.Why doe|
|00006230| 73 6e 27 74 20 74 68 65 | 20 63 6f 64 65 20 64 6f |sn't the| code do|
|00006240| 75 62 6c 65 20 64 3b 20 | 73 63 61 6e 66 28 22 25 |uble d; |scanf("%|
|00006250| 66 22 2c 20 26 64 29 3b | 20 77 6f 72 6b 3f 0a 0a |f", &d);| work?..|
|00006260| 41 3a 09 55 6e 6c 69 6b | 65 20 70 72 69 6e 74 66 |A:.Unlik|e printf|
|00006270| 2c 20 73 63 61 6e 66 20 | 75 73 65 73 20 25 6c 66 |, scanf |uses %lf|
|00006280| 20 66 6f 72 20 64 6f 75 | 62 6c 65 2c 20 61 6e 64 | for dou|ble, and|
|00006290| 20 25 66 20 66 6f 72 20 | 66 6c 6f 61 74 2e 0a 0a | %f for |float...|
|000062a0| 31 31 2e 35 3a 09 57 68 | 79 20 77 6f 6e 27 74 20 |11.5:.Wh|y won't |
|000062b0| 74 68 65 20 63 6f 64 65 | 20 22 77 68 69 6c 65 28 |the code| "while(|
|000062c0| 21 66 65 6f 66 28 69 6e | 66 70 29 29 20 7b 0a 09 |!feof(in|fp)) {..|
|000062d0| 66 67 65 74 73 28 62 75 | 66 2c 20 4d 41 58 4c 49 |fgets(bu|f, MAXLI|
|000062e0| 4e 45 2c 20 69 6e 66 70 | 29 3b 20 66 70 75 74 73 |NE, infp|); fputs|
|000062f0| 28 62 75 66 2c 20 6f 75 | 74 66 70 29 3b 20 7d 22 |(buf, ou|tfp); }"|
|00006300| 20 77 6f 72 6b 3f 0a 0a | 41 3a 09 45 4f 46 20 69 | work?..|A:.EOF i|
|00006310| 73 20 6f 6e 6c 79 20 69 | 6e 64 69 63 61 74 65 64 |s only i|ndicated|
|00006320| 20 5f 61 66 74 65 72 5f | 20 61 6e 20 69 6e 70 75 | _after_| an inpu|
|00006330| 74 20 72 6f 75 74 69 6e | 65 20 68 61 73 20 72 65 |t routin|e has re|
|00006340| 61 63 68 65 64 20 65 6e | 64 2d 0a 09 6f 66 2d 66 |ached en|d-..of-f|
|00006350| 69 6c 65 2e 0a 0a 31 31 | 2e 36 3a 09 57 68 79 20 |ile...11|.6:.Why |
|00006360| 64 6f 65 73 20 65 76 65 | 72 79 6f 6e 65 20 73 61 |does eve|ryone sa|
|00006370| 79 20 6e 6f 74 20 74 6f | 20 75 73 65 20 67 65 74 |y not to| use get|
|00006380| 73 28 29 3f 0a 0a 41 3a | 09 49 74 20 63 61 6e 6e |s()?..A:|.It cann|
|00006390| 6f 74 20 62 65 20 70 72 | 65 76 65 6e 74 65 64 20 |ot be pr|evented |
|000063a0| 66 72 6f 6d 20 6f 76 65 | 72 66 6c 6f 77 69 6e 67 |from ove|rflowing|
|000063b0| 20 74 68 65 20 69 6e 70 | 75 74 20 62 75 66 66 65 | the inp|ut buffe|
|000063c0| 72 2e 0a 0a 31 31 2e 37 | 3a 09 57 68 79 20 64 6f |r...11.7|:.Why do|
|000063d0| 65 73 20 65 72 72 6e 6f | 20 63 6f 6e 74 61 69 6e |es errno| contain|
|000063e0| 20 45 4e 4f 54 54 59 20 | 61 66 74 65 72 20 61 20 | ENOTTY |after a |
|000063f0| 63 61 6c 6c 20 74 6f 20 | 70 72 69 6e 74 66 3f 0a |call to |printf?.|
+--------+-------------------------+-------------------------+--------+--------+
Only 25.0 KB of data is shown above.